douqianmin5367 2018-07-08 17:06
浏览 200

简单的Docker / Nginx错误 - PHP / Laravel

I'm building a PHP and Laravel docker multi-container application by following this tutorial.

It's straight forward and I followed it accurately but I'm running into the following error when running 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

The following is my web.dockerfile that handles the web/nginx service:

FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf

And this is the vhost.conf file which I'm using:

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;
    }
}

Here's the entire docker-compose.yml file holding it all together:

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:

I found this StackOverflow answer that talks about hidden EOL characters but I've tried typing it out myself, and running it through this tool in the same thread.

Any suggestions as to why I might be getting this error?


Update 1
As requested, I'm including the docker history for the web service image that's causing issues:

<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     
  • 写回答

2条回答 默认 最新

  • dousu8456 2018-07-08 18:25
    关注

    As it clearly complains about "unknown directive "listen:" in /etc/nginx/conf.d/default.conf:2". Something wrong in nginx container config.

    To debug it more, I would manually run the web_1 container in intractive mode and should start looking at /etc/nginx/conf.d/default.conf file.

    Else you just rebuild your nginx container.

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?