我正在尝试链接2个单独的容器:
问题是php脚本不起作用。也许php-fpm配置不正确。这是源代码,位于我的资源库中。这是文件docker-compose.yml
:
nginx:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/test/
links:
- fpm
fpm:
image: php:fpm
ports:
- "9000:9000"
以及Dockerfile
我用来基于nginx构建自定义图片的图片:
FROM nginx
# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/
最后,这是我自定义的Nginx虚拟主机配置:
server {
listen 80;
server_name localhost;
root /var/www/test;
error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass 192.168.59.103:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
有人可以帮助我正确配置这些容器以执行php脚本吗?
PS 我像这样通过docker-composer运行容器:
docker-compose up
从项目根目录。
docker exec
进入正在运行的容器并ping fpm吗?
Nginx
并PHP-FPM
一起使用的工作解决方案。如果需要,请查看我的回购github.com/bocharsky-bw/vagrant-ansible-docker。