0

I'm currently stuck on a problem. I got a Server where i run multiple docker.

here i need to put have an php nginx one.

i got a docker-compose file like this :

version: 2
services:
   web:
      image: nginx:latest
      ports:
         - 'XXXX:80'
         - 'XXXX:443'
      volumes:
         - ./code:./code
         - ./site.conf:/etc/nginx/conf.d/default.conf
      environnement:
         - VIRTUAL_HOST:...
         - LETSENCRYPT_HOST:....
         - LETSENCRYPT_MAIL:....
      networks:
         - default
   php:
      build:
         context: ./php
      volumes:
         - ./code:/code
      networks:
         - default
 networks:
   default:
      external:
         name:webproxy

My networks make me getting a automatique letsencrypt ssl

My dockerfile for php is :

FROM php:7.2-fpm
RUN apt-get update \
  && apt-get install -y --no-install-recommends libpq-dev \
  && docker-php-ext-install mysqli pdo_pgsql pdo_mysql

My config is :

server{
  listen 80
  index index.php index.html
  server_name localhost
  error_log /var/log/nginx/error.log
  access_log /var/log/nginx/access.log
  root /code
  location ~ \.php$ {
     try_files $uri =404;
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     fastcgi_pass php 9000;
     fastcgi_index index.php;
     include fastcgi_params;
     fastcgi_param SCIPT_FILENAME $document_root$fastcgi_script_name;
     fastcgi_param PATH_INFO $fastcgi_path_info
  }
}

My structure of folder is something like :

- imgFolder
- GameFolder
    - index.html
    - service.php
    - imgFolder
    - cssFolder
- desktop.html
- mobile.html
- main.css

All seems to be fine web i make my docker-compose compose up -d What i meen by all seems to be fine is : . HTML is well render . SSL is also well apply

But sometimes (not all the time but something like half time) my php file was not found on ajax request (got a 404 file not found in networks debug)

Did someone have an idea of why my service.php is sometimes not found ?

Dunno if it could help but i got exactly the same docker compose working alongside this one (different port) and there is no prob with my php files call.

2
  • what do you see in "Containers" section when you run "docker network inspect webproxy" ? you should only see "web" and "php" containers attached to that network. if you see more than one "php" that may cause a problem.
    – Yarimadam
    Mar 6, 2019 at 21:50
  • I get many container on my network (we are hosting different project on this server which belongs to this network) but no-one have same id or name, docker seems to automaticaly change name with my projectFolder name + service string. Mar 7, 2019 at 8:22

1 Answer 1

3

You are having this issue because you have more than one container with same hostname (php) in same network.

I simulated same scenario, and here is the result.

pinging same hostname, but getting different dns resolutions

3
  • the fact is that for exemple when i make a docker ps my app is well name here i got something like : XXX-php YYY-php XXX-web YYY-web So i didn't understand how i could get conflict between two container. I tried to put something like "test-php" and "test-web" instead of php and web but it always give a 404 Mar 7, 2019 at 12:18
  • Note that containers interact each other with hostnames (service name). Not container names. See you are passing php requests to php:9000, not the XXX-php. (fastcgi_pass php 9000;) You can either seperate the networks or the hostnames. You should change php upstream address if you change hostnames. (eg: fastcgi_pass test-php 9000;)
    – Yarimadam
    Mar 7, 2019 at 12:25
  • Oh ! yeah i miss this line. it seems to work Thanks for your help Mar 7, 2019 at 13:58

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.