Closed kshitij10496 closed 5 years ago
Here is a simple, non-functioning compose file I could come up with:
version: '3'
services:
hercules_db:
image: postgres
ports:
- "5432:5432"
volumes: # Load the SQL dump to the container
- ./hercules_backup_20181020.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- POSTGRES_PASSWORD: postgres
- POSTGRES_USER: postgres
hercules_api:
build: .
ports:
- "8080:8080"
volumes:
- .:/go/src/github.com/kshitij10496/hercules
depends_on:
- db
environment:
- PORT=8080
- HERCULES_DATABASE=#TODO: Update the connection string
@icyflame Could you help me with this? 😅
Ping @icyflame
@kshitij10496 This compose looks fine for two containers. You need to write a Dockerfile for the hercules_api container that will take the go code and run the server.
A common pattern I have seen is people compile the code and copy only the binary to the container from the host, instead of copying the whole thing.
A common pattern I have seen is people compile the code and copy only the binary to the container from the host, instead of copying the whole thing.
Oh yes! We already have a got a multi-stage build Dockerfile in the house 🎉
The issues I'm facing are related to the PostgreSQL, specifically:
RUN
rule in DockerfilesAs long as you use docker-compose, you won't even need to worry about the network stuff. Docker-compose does some magic for you.
A good way to test it would be:
This way, you will find out the exact connection string to use inside your app/ORM.
It would be wonderful if we can get the application to run via a single command. This would involve the use of
docker-compose
for managing multiple containers. Ideally, we should have 2 services - one for the Postgres DB and another for the API.