nuest / ten-simple-rules-dockerfiles

Ten Simple Rules for Writing Dockerfiles for Reproducible Data Science
https://doi.org/10.1371/journal.pcbi.1008316
Creative Commons Attribution 4.0 International
64 stars 15 forks source link

ENV and ARG #70

Closed nuest closed 4 years ago

nuest commented 4 years ago

We don't mention the ENV instruction at all. Does it add anything to an existing rule?

@davclark suggest it to pass metadata to programs inside the container: https://hyp.is/CsguqIDVEeqTU8uVjTPfvA/osf.io/fsd7t/

vsoch commented 4 years ago

I see a few use cases for environment, and it would be worth a mention somewhere. Here is a quick shot for discussion:

The ENV directive for the Dockerfile allows for defining environment variables to persist inside the container ref. Environment variables can be useful for setting software versions and metadata intended to be discovered by installed libraries or software, or for adding binaries to the path (PATH) or library path (LD_LIBRARY_PATH). The user should be careful to distinguish these environment variables from those that might vary and be required at runtime. For runtime environment variables either to set a new variable or override one set in the container, they can be set with the --env directive, or via using a docker-compose.yml file. For variables that are needed to be set at build time, the user is directed to use the ARG directive instead ref.

vsoch commented 4 years ago

So in summary:

nuest commented 4 years ago

I've made the following change, with the reasoning that ARG is a way to create multiple variants of images based on a single Dockerfile, which IMO is something that is not a good practice for our data science scenario (goes against the "one Dockerfile per project" concept). Dev and prod are not ways that scientists think, having one environment under control is already plenty of work.

ENV can be used to pass runtime configuration or to avoid defining a value at multiple places (thinking of it, ARG can, too, but only at build time). ENV is indeed useful to properly install tools (add to path like you describe above).


One use of ARG that might be interesting: passing the git revision. Mentioned that in the text, could be added to the example because it nicely links Dockerfile and repository. But needs a Makefile :shrug:.