What’s the Best Way to Manage Docker for Development and Production?

0
6
Asked By CleverGiraffe42 On

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

Answered By DockerDude99 On

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!

TechWhiz01 -

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.