Is there yet any native or commonly-accepted approaches to using environment variables to control Docker behaviour, i.e. in a 12factor manner?
The only language-agno
Docker 0.10.0 and newer (Apr 8, 2014) accepts docker run --env-file <filename>
, which lets you feed docker's running environment with .env
-like files.
Moreover, you can let dockers to interact further: --volumes-from
can mount all volumes from the referenced container, and --link
lets the container know the details of the referenced container's exposed ports.
While the Docker run reference is a bit weak at the moment, you can find all the details in the CLI reference's run section, as well as the container linking reference.
As of what to start from the container. Usually I recommend starting a shell script, which sets default environment variables (along the lines of : ${ENV:=default_value}
), exports them, then exec
s a single executable. This executable can be the desired application in the foreground, or an init replacement like runit
or supervisord
.
I wouldn't recommend running sshd
inside your docker, if it's not part of the system (for example, a container for gitlab should contain sshd, as it provides git repo access through ssh). For maintenance or debugging purposes I recommend using nsenter
instead.