I'm working on a Go backend that requires Postgres and possibly other services, and I seem to always hit the same roadblock. I typically end up writing a `docker-compose.dev.yaml` file that launches my dependencies, then I run my app with `go run main.go`.
While I could rebuild my Docker image every time, it makes me wonder if there's a more efficient way. Rebuilding isn't too slow with caching, but it forces me to restart the Postgres container often. This means waiting for it to be healthy again, which can be a pain.
I also face issues with health checks since they run every 5 seconds by default, which is quite annoying during development. When I make changes to my Go app and run `docker compose up --build`, it restarts the Postgres service, which is something I want to avoid. Is there a way to only restart the Go container while leaving Postgres running, or should I just stick with different Docker files for each environment?
1 Answer
You really don’t need to bring down your Postgres every time. Just build and start your app container by specifying its name with `docker compose up -d --build app`. That way, Postgres stays up while you tweak your app!
Exactly! I've had success just doing a `docker compose up` for the app. Docker recreates containers as needed based on any changes you made in config or images.