Ao fazer o "docker compose up", tanto com o zip quanto com o projeto do github recebi o erro abaixo:
Attaching to app-1, postgres-1
postgres-1 | Error: in 18+, these Docker images are configured to store database data in a
postgres-1 | format which is compatible with "pg_ctlcluster" (specifically, using
postgres-1 | major-version-specific directory names). This better reflects how
postgres-1 | PostgreSQL itself works, and how upgrades are to be performed.
postgres-1 |
postgres-1 | See also https://github.com/docker-library/postgres/pull/1259
postgres-1 |
postgres-1 | Counter to that, there appears to be PostgreSQL data in:
postgres-1 | /var/lib/postgresql/data (unused mount/volume)
postgres-1 |
postgres-1 | This is usually the result of upgrading the Docker image without
postgres-1 | upgrading the underlying database using "pg_upgrade" (which requires both
postgres-1 | versions).
postgres-1 |
postgres-1 | The suggested container configuration for 18+ is to place a single mount
postgres-1 | at /var/lib/postgresql which will then place PostgreSQL data in a
postgres-1 | subdirectory, allowing usage of "pg_upgrade --link" without mount point
postgres-1 | boundary issues.
postgres-1 |
postgres-1 | See https://github.com/docker-library/postgres/issues/37 for a (long)
postgres-1 | discussion around this process, and suggestions for how to do so.
postgres-1 exited with code 1
app-1 |
app-1 | 2026/05/29 17:32:29 /app/database/db.go:23
app-1 | [error] failed to initialize database, got error failed to connect to host=postgres user=root database=root: hostname resolving error (lookup postgres on 127.0.0.11:53: server misbehaving)
app-1 | 2026/05/29 17:32:29 Erro ao se conectar com o banco de dados
app-1 | panic: Erro ao se conectar com o banco de dados
app-1 |
app-1 | goroutine 1 [running]:
app-1 | log.Panic({0xc00013de70?, 0xc00068e000?, 0x0?})
app-1 | /usr/local/go/src/log/log.go:432 +0x5a
app-1 | github.com/guilhermeonrails/api-go-gin/database.ConectaComBancoDeDados()
app-1 | /app/database/db.go:25 +0x30c
app-1 | main.main()
app-1 | /app/main.go:9 +0xf
app-1 exited with code 2
Tive sucesso ao fazer algumas alterações no .yaml para que ele ficasse assim:
services:
postgres:
image: "postgres"
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- POSTGRES_DB=root
ports:
- 5432:5432
volumes:
- ./postgres-data:/var/lib/postgresql # note: no '/data'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U root -d root"]
interval: 5s
timeout: 5s
retries: 5
app:
build:
context: .
target: production
ports:
- 8080:8080
environment:
- DB_HOST=postgres
- DB_USER=root
- DB_PASSWORD=root
- DB_NAME=root
- DB_PORT=5432
depends_on:
postgres:
condition: service_healthy