我正在通过this tutorial构建一个PHP和Laravel docker多容器应用程序。
它很简单,我准确地遵循了它,但在运行docker-compose up
时遇到了以下错误
database_1 | 2018-07-08 16:51:11 1 [Note] mysqld: ready for connections.
database_1 | Version: '5.6.40' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
app_1 | [08-Jul-2018 15:02:52] NOTICE: fpm is running, pid 1
app_1 | [08-Jul-2018 16:51:10] NOTICE: ready to handle connections
web_1 | 2018/07/08 16:52:24 [emerg] 1#1: unknown directive "listen:" in /etc/nginx/conf.d/default.conf:2
web_1 | nginx: [emerg] unknown directive "listen:" in /etc/nginx/conf.d/default.conf:2
see-number_web_1 exited with code 1
下面是我处理web/nginx服务的web.dockerfile
:
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
这是我正在使用的vhost.conf
文件:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
下面是包含所有内容的整个docker-compose.yml
文件:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
我发现this StackOverflow answer讨论了隐藏的EOL字符,但我尝试自己输入它,并在同一线程中通过this tool运行它。
对于为什么我会收到这个错误,有什么建议吗?
更新1
按照要求,我包含了导致问题的web服务镜像的docker history
:
<user>:<project> <user>$ docker history see-number_web
IMAGE CREATED CREATED BY SIZE COMMENT
5c0285cb9dd2 6 hours ago /bin/sh -c #(nop) ADD file:4387275b028088cf9… 453B
0346349a1a64 15 months ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> 15 months ago /bin/sh -c #(nop) EXPOSE 443/tcp 80/tcp 0B
<missing> 15 months ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B
<missing> 15 months ago /bin/sh -c apt-key adv --keyserver hkp://pgp… 58.2MB
<missing> 15 months ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.10.3-… 0B
<missing> 15 months ago /bin/sh -c #(nop) MAINTAINER NGINX Docker M… 0B
<missing> 15 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 15 months ago /bin/sh -c #(nop) ADD file:4eedf861fb567fffb… 123MB
发布于 2018-07-09 02:25:30
因为它清楚地抱怨“未知指令”:“in /etc/nginx/conf.d/default.conf:2”。nginx容器配置中出现错误。
为了对其进行更多的调试,我将在内部模式下手动运行web_1容器,并且应该开始查看/etc/nginx/conf.d/default.conf文件。
否则,您只需重新构建您的nginx容器。
发布于 2018-07-09 07:23:53
对于在类似或类似的过程中可能遇到奇怪错误的任何人:
我不得不docker rmi
任何与我的docker-compose.yml
关联的图像。我相信之前需要重建的时候缓存了一些图像。更改文件并运行docker-compose up
不会清除或重建任何内容-因此,删除图像并再次执行完整的docker-compose up
是可行的。
https://stackoverflow.com/questions/51234277
复制相似问题