To build the Docker Compose file, make sure you are in the same directory as the file.
$ docker-compose build
Run the docker-compose
$ docker-compose up -d
The API server will make multiple attempts to connect to the PostgreSQL database in case of failure. Therefore, if you encounter an error message like the one below, there is no need to worry:
root-api-1 | [error] failed to initialize database, got error failed to connect to `host=postgres user=root database=senao`: dial error (dial tcp 172.18.0.2:5432: connect: connection refused)
Check docker to ensure that both the API server and PostgreSQL are running. If you see something similar to the following, it means everything is working well.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e53ef45e278 amboseqiu/senao_hw "/app/main" 7 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp senao_hw-api-1
b8f1d75b6685 postgres:14-alpine "docker-entrypoint.sā¦" 7 seconds ago Up 6 seconds 0.0.0.0:5432->5432/tcp senao_hw-postgres-1