4

I download official docker packages, and then I set docker-compose. Everything compiles OK, but if I get docker-compose up, I got this error message:

project-websrv | 2017/09/22 10:18:35 [emerg] 1#1: host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-websrv | nginx: [emerg] host not found in upstream "php-fpm" in /etc/nginx/conf.d/default.conf:25
project-php exited with code 0

nginx.conf line 25:

fastcgi_pass php-fpm:9000;

my docker-compose.yml

version: "3.1"
services:

    mysql:
      image: mariadb
      container_name: project-mariadb
      environment:
        MYSQL_ROOT_PASSWORD: root

    phpmyadmin:
      image: phpmyadmin/phpmyadmin
      container_name: project-pma
      restart: always
      links:
        - mysql
      ports:
        - 8183:80
      environment:
        PMA_HOST: mysql
        PMA_USER: root
        PMA_PASSWORD: root

    php-fpm:
      build: php
      container_name: project-php
      working_dir: /var/www/project
      volumes:
        - ../../Sources/project/trunk/src/:/var/www/project
        - ./php/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-overrides.ini
      links:
        - mysql      

    webserver:
      image: nginx
      container_name: project-websrv
      working_dir: /var/www/project
      volumes:
          - ../../Sources/project/trunk/src/:/var/www/project
          - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf  
      ports:
       - "8080:80"
      links:
       - php-fpm

Folder structure:

php/
 - Dockerfile
 - php-ini-overrides.ini
mysql/
nginx/
 - nginx.conf
*docker-compose.yml

full nginx.conf

server {
    listen 80 default;

    client_max_body_size 108M;

    access_log /var/log/nginx/application.access.log;

    root /var/www/project/web;
    index app_dev.php;

    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    try_files $uri @rewriteapp;

    location @rewriteapp {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    # Deny all . files
    location ~ /\. {
        deny all;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass php-fpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;
    }

    # Statics
        location /(bundles|media) {
        access_log off;
        expires 30d;
        try_files $uri @rewriteapp;
    }
}

I check URL twice and everything seems like be ok, nginx.conf is set and store in this URL. The Same configuration I use for another container, only without phpmyadmin and mariadb, and it works fine.

Jan Sršeň
  • 1,045
  • 3
  • 23
  • 46
  • could you please show me /etc/nginx/conf.d/default.conf ? – Bukharov Sergey Sep 22 '17 at 11:31
  • I add it upper, but it is maybe problem of docker cache, because, before I use same names for another container, but before build this I restart docker – Jan Sršeň Sep 22 '17 at 11:39
  • I do not sure, But i think when nginx is run it try to connect to `php-fpm` host. And `php-fpm` container may be is not started yet. I did not work with `fastcgi_pass`, but for `proxy pass` works solution: add `resolver 127.0.0.11;` onto `location ~ ^/(app|app_dev)\.php(/|$)` section . – Bukharov Sergey Sep 22 '17 at 11:47
  • Ok, I reset docker to the factory, delete all containers and images. But I got these error: `ERROR: for project-websrv Cannot start service webserver: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: . . . . : Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type` – Jan Sršeň Sep 22 '17 at 13:06
  • I send this container to my friend and on his machine works everything fine – Jan Sršeň Sep 22 '17 at 13:07
  • which os are using docker on? Give the infrastructure details please – Tarun Lalwani Sep 22 '17 at 16:25
  • Windows 10 64bit Professional and Docker with Autoupdate – Jan Sršeň Sep 22 '17 at 18:31
  • 5
    Did you ever get to solve this issue? I'm having the exact one right now, and I'm about to loose my head – samayo Oct 10 '18 at 21:59

1 Answers1

3

I found some help in the documentation on how to add aliases: https://docs.docker.com/compose/compose-file/#aliases

services:
  # ...
  php-fpm:
    # ... 
    networks:
      proxy: # maybe use "default" here
        aliases:
        - php-fpm
  webserver:
    # ...
    links: # seems to have no effect alone
    - php-fpm
    networks:
    - proxy # maybe you can also use the "default" network
    depends_on: # start this container after the dependencies
    - php-fpm

networks:
  proxy:

This answer could be simplified with your feedback. What do you really need to add?

User
  • 14,131
  • 2
  • 40
  • 59