0

I am starting following a course on Udemy. This couse uses Docker and I am finding the following problem. I am using Ubuntu 20.04 as operating system.

I have this docker-compose.yml file (provided as course resource):

version: '3.3'

networks: 
  ntpgsql:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.21.0.0/24

services:
  pgsql:
    image: postgres:latest
    restart: unless-stopped
    container_name: postgresql
    volumes: 
      - psdb-volume:/var/lib/postgresql/data
    networks: 
      ntpgsql:
        ipv4_address: 172.21.0.2
    ports:
      - target: 5432
        published: 5433 
        protocol: tcp
        mode: host
    environment:
      - POSTGRES_PASSWORD=123_Stella
  pgadmin:
    image: dpage/pgadmin4
    restart: unless-stopped
    container_name: pgadmin4
    
    networks:
      ntpgsql:
        ipv4_address: 172.21.0.3
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
    environment:
      - PGADMIN_CONFIG_SERVER_MODE=True
      - PGADMIN_DEFAULT_EMAIL=may-email@gmail.com
      - PGADMIN_DEFAULT_PASSWORD=123_Stella


volumes:
  psdb-volume:

So I accessed to the directory containing this configuration file and from my shell I performed this command to download and start rthese two containers defined into my configuration file:

docker-compose up

Images seems to be correctly downloaded but, at the end, I obtain this error message when it try to start the containers:

Status: Downloaded newer image for dpage/pgadmin4:latest
Creating pgadmin4 ... 
Creating pgadmin4   ... error
WARNING: Host is already in use by another container

ERROR: for pgadmin4  Cannot start service pgadmin: driver failed programming external connectivity on endpoint pgadmin4 (a1643d333555ed47a666d5df57ab5db20a1f5e0a141fe6026f135689b1b7541d): Error starting userland proxy: listen tcp4 0.0.0.0:8Creating postgresql ... done

ERROR: for pgadmin  Cannot start service pgadmin: driver failed programming external connectivity on endpoint pgadmin4 (a1643d333555ed47a666d5df57ab5db20a1f5e0a141fe6026f135689b1b7541d): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use
ERROR: Encountered errors while bringing up the project.
andrea@ubuntu:~/Documents/spirng-microservies-course$ docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED              STATUS              PORTS                                       NAMES
8467ee204a9d   postgres:latest   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:5433->5432/tcp, :::5433->5432/tcp   postgresql

It seems to me that it have correctly started the first container listed in my configuration file (the one named postgresql) but not the second one (named pgadmin4).

What could be the problem? How can I try to fix it?

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • The port may be in use by a stopped container. Try `docker ps -a` to see stopped containers. Then remove the ones you don't need using `docker rm ` – Hans Kilian Oct 15 '21 at 19:30
  • An Apache or Nginx server running on your host, not in a container, could also cause this. The easiest workaround is to change the `ports: [{ published: }]` value, but the linked question also has some suggestions on finding the host process with the port. – David Maze Oct 15 '21 at 22:18
  • (P.S.: the `docker-compose.yml` file could be dramatically shorter. You should be able to delete all of the `networks:` blocks; Compose will create a network named `default` for you and automatically assign IP addresses. You don't need to set `container_name:`, and there's a much shorter `ports: ['5433:5432']` syntax.) – David Maze Oct 15 '21 at 22:19

0 Answers0