0

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
  • Nginx server blocks need to be contained within http blocks. Is that conf file being included by nginx.conf? Commented Jul 8, 2018 at 17:31
  • @DigitalDrifter considering I followed the tutorial accurately, could you please elaborate on what you mean, possibly with an example? And I believe my web.dockerfile is including it properly. Do you see a reason why it wouldn't be? Commented Jul 8, 2018 at 17:34

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Could you please elaborate on how to build that exact container in interactive mode. I know I'll build it by using: docker-compose build web. But how do I do this interactive mode that you're talking about, and what will it benefit?
Not to get confused (What i meant by interactive mode )If i am interested in troubleshooting more into the current error, then i would fire up the container from the image which is already created(web_1) and start checking at the nginx config file after opening up a bash session.
Some answers that I linked to in the question were talking about EOL (end of line) characters. Could there be anything besides that happening in your opinion? Also, I can't fire up the container because it exited with status 1. I can get into the other containers, just not that one.
possibly yes, But cant confirm unless we see. Can you post your docker history for your image file?
I posted the docker history <project>_web but I don't believe this will be of much service because I directly pulled down the nginx:1.10 image in my web.dockerfile, therefore I haven't edited it in any way. Is there any other diagnostic information I could provide?
|
1

For anyone that may encounter weird errors during a process like this or similar to it:

I had to docker rmi any images that were associated with my docker-compose.yml. I believe some image was cached from earlier when it actually needed to be rebuilt. Changing files and running docker-compose up doesn't clear or rebuild anything - therefore deleting images and doing a full docker-compose up again worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.