0

I'm new to docker-compose but my intuition is that it should not matter at all how a service is named, like a variable in a programming language. Is that correct and is there some obscure bug or is there some magic in the background that I don't understand?

The following example from the bitnami phppgadmin repository only works if the service is named exactly "postgresql":

version: '2'
services:
  postgresql:
    image: docker.io/bitnami/postgresql:11
    environment:
      - POSTGRESQL_PASSWORD=bitnami
    volumes:
      - 'postgresql_data:/bitnami'
  phppgadmin:
    image: docker.io/bitnami/phppgadmin:7
    ports:
      - '80:8080'
      - '443:8443'
    depends_on:
      - postgresql
volumes:
  postgresql_data:
    driver: local

As soon as I rename the service to anything else, it breaks with a "login failed" in the phppgadmin interface with no further information neither on the page nor in the docker compose logs:

version: '2'
services:
  foo:
    image: docker.io/bitnami/postgresql:11
    environment:
      - POSTGRESQL_PASSWORD=bitnami
    volumes:
      - 'postgresql_data:/bitnami'
  phppgadmin:
    image: docker.io/bitnami/phppgadmin:7
    ports:
      - '80:8080'
      - '443:8443'
    depends_on:
      - foo
volumes:
  postgresql_data:
    driver: local

I am using docker-compose down and then docker-compose up to make sure there is no leftover container from a previous run.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 30 '21 at 07:55

1 Answers1

1

The service name, in this case postresql, represents the name of the host for other Docker containers to address. By switching the service name to foo you now have a container that can be addressed with that hostname.

by default phppgadmin looks for Postgresql to be running on a host named postsgresql, you can change this by passing the DATABASE_HOST environment variable to the phppgadmin container.

phppgadmin:
  image: docker.io/bitnami/phppgadmin:7
  ports:
    - '80:8080'
    - '443:8443'
  environment:
    - DATABASE_HOST=foo  
  depends_on:
    - foo
swysocki
  • 818
  • 5
  • 8