我下载了官方的docker包,然后我设置了docker-compose。一切都编译好,但如果我得到 docker-compose up ,我收到此错误消息:
project-websrv | 2017/09/22 10:18:35 [emerg] 1#1: host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-websrv | nginx: [emerg] host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-php exited with code 0
nginx.conf 第25行:
fastcgi_pass php-fpm:9000;
我的 docker-compose.yml
version: "3.1"
services:
mysql:
image: mariadb
container_name: project-mariadb
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: project-pma
restart: always
links:
- mysql
ports:
- 8183:80
environment:
PMA_HOST: mysql
PMA_USER: root
PMA_PASSWORD: root
php-fpm:
build: php
container_name: project-php
working_dir: /var/www/project
volumes:
- ../../Sources/project/trunk/src/:/var/www/project
- ./php/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-overrides.ini
links:
- mysql
webserver:
image: nginx
container_name: project-websrv
working_dir: /var/www/project
volumes:
- ../../Sources/project/trunk/src/:/var/www/project
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
links:
- php-fpm
文件夹结构:
php/
- Dockerfile
- php-ini-overrides.ini
mysql/
nginx/
- nginx.conf
*docker-compose.yml
完整的nginx.conf
server {
listen 80 default;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
root /var/www/project/web;
index app_dev.php;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri @rewriteapp;
location @rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
# Deny all . files
location ~ /\. {
deny all;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index app.php;
send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
# Statics
location /(bundles|media) {
access_log off;
expires 30d;
try_files $uri @rewriteapp;
}
}
我检查了两次URL,一切似乎都没问题,nginx.conf已设置并存储在此URL中。我用于另一个容器的相同配置,只有没有phpmyadmin和mariadb,它工作正常。
答案 0 :(得分:1)
我在文档中找到有关如何添加别名的帮助: https://docs.docker.com/compose/compose-file/#aliases
services:
# ...
php-fpm:
# ...
networks:
proxy: # maybe use "default" here
aliases:
- php-fpm
webserver:
# ...
links: # seems to have no effect alone
- php-fpm
networks:
- proxy # maybe you can also use the "default" network
depends_on: # start this container after the dependencies
- php-fpm
networks:
proxy:
您的反馈可以简化此答案。您真正需要添加什么?