我想要将两个独立的容器连接起来:
问题在于,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"
以下是我用来基于 nginx 镜像构建自定义镜像的 Dockerfile
:
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脚本吗?
P.S. 我通过像这样的docker-compose运行容器:
docker-compose up
从项目根目录中运行。
docker exec
进入正在运行的容器并ping fpm? - Vincent De SmetNginx
和PHP-FPM
与 Vagrant 和 Ansible 链接在一起。如果您有兴趣,请查看我的存储库 https://github.com/bocharsky-bw/vagrant-ansible-docker。 - Victor Bocharsky