K
K
Konstantin B.2021-03-15 08:44:29
Docker
Konstantin B., 2021-03-15 08:44:29

What can cause this Postgress error in DockerCompose?



Often an error occurs due to the fact that postgres falls off SQLSTATE [08006] [7] could not translate host name "postgres" to address: Temporary failure in name docker-compose up -dresolution docker gurus. For example, it was necessary to restart the computer, preloaded, all containers started, but postgress did not. I had to do it manuallydocker-compose up -d

docker-compose.yml

version: '3'
services:

  #PHP Service
  app:
    build:
      args:
        user: ubuntu
        uid: 1000
      context: .
      dockerfile: docker/Dockerfile
    image: digitalocean.com/php
    restart: unless-stopped
    tty: true
    working_dir: /var/www
    volumes:
      - ./code:/var/www
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    links:
      - postgres
    networks:
      - app-network

  #Nginx Service
  webserver:
    image: nginx:alpine
    restart: unless-stopped
    tty: true
    ports:
      - 9680:80
    volumes:
      - ./code:/var/www:cached
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
    networks:
      - app-network

  # PostgreSQL database container
  postgres:
    build:
      context: docker/postgres
      dockerfile: Dockerfile
    volumes:
      # Database volume
      - database:/var/lib/postgresql/data
      # Temp volume to allow using dumps
      - ./docker/postgres/dumps/:/tmp/
    ports:
      - 54321:5432
    environment:
      - LC_ALL=C.UTF-8
      - POSTGRES_DB=app
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=app
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge
#Volumes
volumes:
  database:
    driver: local

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KoreanGuy, 2021-03-15
@KoreanGuy

your compose is running 3 containers on the same subnet (app-network). In this subnet (and only in it), the names of services (app, webserver, postgres) can be used instead of their IP. That is, your app container can, for example, connect to a database using postgres:5432 as the address. But you can't, say, connect to a postgres container by that name from somewhere outside the subnet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question