Docker Compose container in Nginx does not route correctly

2

I'm getting started on this Docker container and following a tutorial, I created a docker-compose.yml file to have a web application server based on Nginx , PHP7-fpm , MySQL and Laravel (all in their latest versions).

It works but not as it should because when I access the IP service shows me the Nginx page instead of Laravel .

I'm using Ubuntu 16.04.2 64bits and Docker Compose . The code of the YML file is as follows:

# 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.7
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
        - "33061:3306"

volumes:
  dbdata:

The web configuration file is this:

FROM nginx:latest
ADD vhost.conf /nginx/conf.d/default.conf
# Añadido por mi a ver si enruta bien
WORKDIR /var/www

The vhost.conf is this:

server {
    listen 80;
    index index.php index.html;
    root /var/www/public;

    location / {
        try_files $uri /index.php?$args;
    }

    location ~ \.php$ {
        fastcig_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_parm SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

The application is as follows:

FROM php:7.0.15-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
    
asked by Pedrog 19.03.2017 в 15:13
source

1 answer

0

The first thing I see is that in your vhost.conf you are indicating that the fastcgi_pass parameter points to app: 9000 , which I imagine will be the PHP-FPM container.

Well this will never work, since you do not "see" the containers between them unless you link them or place them within the same network .

Add to the end of your docker-compose this:

networks:
  appnet:
   driver: bridge

And then in each service you add:

networks:
  - appnet

And with that you are indicating that each service belongs to the same "network". That way the container nginx will know who is app .

I hope I have helped you!

    
answered by 06.02.2018 в 17:17