Docker 2 web apps on same network

  docker, nginx, yaml

Is it possible to have 2 separate web apps on 2 different ports in the same network?

I have a working container on localhost:8000 and now I want something else on localhost:8100

My docker-compose.yaml has this nginx server:

services:
    server:
        build:
            context: .
            dockerfile: dockerfiles/prod/nginx.dockerfile
        ports:
            - "8000:8000"
            - "8100:8100"

I have 2 settings in the nginx conf, port 8000 works, but I get a 404 with port 8100:

server {
    listen 8000;
    index index.php index.html;
    server_name localhost;
    root /var/www/html/public;
    client_max_body_size 20M;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_read_timeout 120; 
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
server {
    listen 8100;
    index index.php index.html;
    server_name localhost;
    root /var/www/html;
    client_max_body_size 20M;
    location / {
        try_files $uri /index.php?$query_string;
    }
    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass googleapi:9000;
        fastcgi_read_timeout 120; 
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

(I’m not sure if this line is correct: fastcgi_pass googleapi:9000)

My docker-compose.yaml has googleapi app like so:

googleapi:
    image: php:8.0-apache
    expose:
        - "9000"
    volumes:
        - ./php/:/var/www/html/
    container_name: toolkit-googleapi

However when I navigate to localhost:8100 I get an nginx 404:

404 nginx

I have an index.php file inside /var/www/html

I’m rubbish at networking so I may have missed something completely obvious. Any help appreciated.

Source: Docker Questions

LEAVE A COMMENT