skip to Main Content

I use docker-compose to set up a web service connected to a postgresql database. When I run docker-compose up -d, both mydb and web services are created, but the database is not reachable from the web service. I cannot understand why.

services:
  web:
    image: etherpad/etherpad:1.8.10
    depends_on:
      mydb:
        condition: service_healthy
    ports:
      - "6080:9001"
    environment:
      - DB_TYPE=postgres
      - DB_PORT=5432
      - DB_HOST=mydb
      - DB_NAME=postgres
      - DB_USER=etherpad
      - DB_PASS=mydbpass
  mydb:
    image: postgres:13
    expose:
      - 5432
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=mydbpass
      - POSTGRES_USER=etherpad
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it with :

    systemctl stop nftables
    systemctl start docker
    systemctl disable nftables
    reboot
    systemctl start docker
    

    see: http://github.com/moby/moby/issues/36151#issuecomment-968356070


  2. For 2 containers (=instance of service) to communicate you need a network between them.

    Indeed depends_on is not enough, it just adds constraints on start-up/build.

    services:
      web:
        image: etherpad/etherpad:1.8.10
        depends_on:
          mydb:
            condition: service_healthy
        ports:
          - "6080:9001"
        environment:
          - DB_TYPE=postgres
          - DB_PORT=5432
          - DB_HOST=mydb
          - DB_NAME=postgres
          - DB_USER=etherpad
          - DB_PASS=mydbpass
        networks:
          - backend
      mydb:
        image: postgres:13
        expose:
          - 5432
        environment:
          - POSTGRES_DB=postgres
          - POSTGRES_PASSWORD=mydbpass
          - POSTGRES_USER=etherpad
        healthcheck:
          test: ["CMD-SHELL", "pg_isready"]
          interval: 10s
          timeout: 5s
          retries: 5
        networks:
          - backend
    networks:
      backend:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search