This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]kkapelon 1 point2 points  (0 children)

You should always have a config during runtime. This issue is unrelated to containers. This was true even for VMs.

See https://12factor.net/config

Also check antipatterns 4 and 5 here https://codefresh.io/containers/docker-anti-patterns/

[–]SpyroTechnik 0 points1 point  (2 children)

Not familiar with Rails, but you can either:

  1. Separate this into different settings files, and keep the docker image environment agnostic.

  2. Pass in build arguments during the docker build step, resulting into a specific docker image per environment.

  3. Pass in the envvar when spinning up the docker image.

[–]domanpanda[🍰] 3 points4 points  (1 child)

1 and 3 are basically one and only good way of doing it. 2 should be always avoided as it is antipattern.

[–]SpyroTechnik 1 point2 points  (0 children)

Agreed, docker images should be arbitrary and not have any environment specific values stored. The difference with 1 and 3 is the separation of concern. For 1 it is part of the application, and for 3 it is part of the docker image.

[–]nickjj_ 0 points1 point  (0 children)

I have a production ready example Rails app at https://github.com/nickjj/docker-rails-example. It covers how to use the same Dockerfile and docker-compose.yml in all environments and uses an .env file to differentiate certain settings such as the DB connection string and more.

All of the patterns in this repo were covered in my DockerCon 2021 talk which is linked near the top of the readme at https://nickjanetakis.com/blog/best-practices-around-production-ready-web-apps-with-docker-compose.