I'm trying to use a following config:
docker-compose.yml
version: "3"
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: onjin/alpine-postgres
environment:
POSTGRES_PASSWORD: password
The other file is Dockerfile:
FROM alpine
RUN apk update && apk add --no-cache postgresql-client
COPY Bot/ /Bot
ENV PGHOST=db PGPASSWORD=password
RUN psql -h "$PGHOST" -f /Bot/test/database_schema.sql
I have no idea why I always get this error while running "docker-compose up":
psql: could not translate host name "db" to address: Name does not resolve
Can anyone help me with debugging this? Seems like the "db" hostname is not being propagated inside the docker environment, but don't know the reason for that.
depends_onguarantees that you container is up, but it does not guarantee that the database is ready to receive connections. It takes some time for Postgres to be ready after the container starts. Try to see the logs and try toexecinto your image and run the command manually after you give some time to Postrgres to get up.