Ao executar o comando: docker compose up aparece o seguinte erro:
docker compose up
[+] Running 1/1
✔ postgres Pulled 1.3s
[+] Running 2/2
✔ Container 3983-integracao-continua-app-1 Created 0.0s
✔ Container 3983-integracao-continua-postgres-1 Recreated 0.3s
Attaching to app-1, postgres-1
app-1 | 2025/07/03 14:35:44 Erro ao conectar com banco de dados
app-1 |
app-1 | 2025/07/03 14:35:44 /app/database/db.go:24
app-1 | [error] failed to initialize database, got error failed to connect to `host=postgres user=root database=root`: dial error (dial tcp 172.18.0.2:5432: connect: connection refused)
app-1 | panic: Erro ao conectar com banco de dados
app-1 |
app-1 | goroutine 1 [running]:
app-1 | log.Panic({0xc000593e70?, 0xc00006d1e0?, 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:26 +0x30c
app-1 | main.main()
app-1 | /app/main.go:9 +0xf
app-1 | exit status 2
postgres-1 |
postgres-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres-1 |
postgres-1 | 2025-07-03 14:35:44.517 UTC [1] LOG: starting PostgreSQL 17.5 (Debian 17.5-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
postgres-1 | 2025-07-03 14:35:44.517 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres-1 | 2025-07-03 14:35:44.518 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres-1 | 2025-07-03 14:35:44.532 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
app-1 exited with code 1
postgres-1 | 2025-07-03 14:35:44.611 UTC [29] LOG: database system was shut down at 2025-07-03 14:35:37 UTC
postgres-1 | 2025-07-03 14:35:44.660 UTC [1] LOG: database system is ready to accept connections