Looking For A Recommendation Of Where To Stash Docker Artifacts

So I’ve got a couple of questions:

1.) Assuming I’ve got a Dockerfile I want to use with an Elixir app, is there a canonical/best practices/standard directory where I’d want to stash this in the Elixir directory tree? Feels like maybe priv but then that also seems like it should be only for Elixir stuff. Same question about a compose.yaml file.

2.) I’m working on dockerizing my postgresql db as well as my Elixir app. Starting the docker container is simple and I can, of course, persist stuff to my local drive. But I’m looking for some input/feedback/suggestions on how I should structure things. For instance I know I can have multiple Dockerfile files each taking care of one of the containers I’m using. I mean starting multiple containers for an app is a compose.yaml thing as far as I can tell but since I can’t have multiple Dockerfiles in the same directory (or can I?) splitting each container into it’s own Dockerfile seems as if it may be problematic.

Any guidance and/or suggestions (including RTFM as long as you point me to the right manual to read) is welcome!

The Dockerfile I always store in the root directory (as it is expected from docker when you want to do a build). The key thing is that all the secrets/parameters you want to pass as ENV variables at runtime. This avoids leaking sensitive credentials outside of deployment.

For deployment there are a range of solutions. The easiest and most effective (especially if you deploy on custom hardware like I usually do) is to have a separate infra repository. That repo holds all the sensitive credentials as well as the docker-compose.yaml.

It seems that you also want to instruct to build the images on your local machines. I would recommend to not do that and to use any kind of CI you have at disposal to build and store images prebuilt, as you won’t gain any value from having the ability to build everything locally.

It honestly doesn’t matter. I’ve seen people put deploy/ directory in the root of the project, I’ve seen dev/ and prod/ directories where Dockerfiles and Compose and Terraform etc. files resided, I’ve seen priv/docker/ as well.

Another trick you can do is utilize GitHub search: Repository search results · GitHub (though it can be refined further, this is just a first attempt) and see how other people might be doing it.

I‘d argue within /priv is the one where there are arguments against. That folder is meant to hold static files the application needs at runtime. Things like migrations for ecto, static assets for phoenix, … That stuff will be bundled with releases of the application.

E.g. a dockerfile is not needed by the elixir application at runtime. It would likely even mean that the dockerfile includes itself in the docker container its describing to be built.

3 Likes

Sure. I’m saying that with Phoenix not actually enforcing file locations, I’ve seen pretty wild setups out there.

Thanks, everyone, for replying. As I say, I didn’t think there was a standard (even an informal one) and I wanted to make sure I wasn’t missing something. Thanks for the thoughtful feedback all!