Docker, changing service name from PHP to different returns 503 Service Unavailable

Viewed 50

I have docker-compose.yml which looks like this.

version: "3.6"
services:
  php:
   build: './php/'
   ports:
     - 9000:9000
   networks:
     - backend
   volumes: 
     - .\puppet_projects\pname\pname:/var/www/html/pname
  apache_pname:
    build: './apache/'
    depends_on:
      - php
    ports: 
      - "80:80"
    networks:
      - frontend
      - backend
    volumes: 
      - .\puppet_projects\pname\pname:/var/www/html/pname
networks:
  frontend:
  backend:

And when I am starting docker-compose up project works properly but after changing php to ie. php_pname I am receiving 503 Site Unavailable

version: "3.6"
services:
  php_pname:
   build: './php/'
   ports:
     - 9000:9000
   networks:
     - backend
   volumes: 
     - .\puppet_projects\pname\pname:/var/www/html/pname
  apache_pname:
    build: './apache/'
    depends_on:
      - php_pname
    ports: 
      - "80:80"
    networks:
      - frontend
      - backend
    volumes: 
      - .\puppet_projects\pname\pname:/var/www/html/pname
networks:
  frontend:
  backend:

What couses error. How can I fix it? Do I have to set up service name to php without changing it?

1 Answers

I suppose you use Apache2 as a proxy and it's configured to pass requests to php service. When you change the service name, it's internal DNS record in Docker changes as well and so Apache is unable to find php anymore.

You can either reflect the change in Apache configuration or add an alias to the php service to give it a second name:

services:
  php_pname:
   build: './php/'
   ports:
     - 9000:9000
   networks:
     backend:
       aliases:
         - php

This way you can access service php_pname from backend network with both php_pname and php.

Related