qarthandso
qarthandso

Reputation: 2190

Simple Docker/Nginx Error - 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     

Upvotes: 0

Views: 698

Answers (2)

qarthandso
qarthandso

Reputation: 2190

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.

Upvotes: 1

Random_Automation
Random_Automation

Reputation: 452

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.

Upvotes: 2

Related Questions