Reputation: 373
I have a Docker container, which uses alpine:3.7
as base image, and as a result, uses /bin/ash
as its shell.
I put the container into background running mode. My intend is that I can continually use docker exec $CONTAINER_ID <command>
at it. Thus, the command would be executed in non-interactive, non-login shell mode.
But, sometimes my <command>
is in a non-standard path, therefore I would like to export PATH
so I don't type fully qualified paths. Or, sometimes some software installation requires me to put some commands in our shell init files (e.g. eval "$(pyenv init -)"
).
The problem is: under /bin/ash
shell, for a non-interactive, non-login shell command execution, where can I export this new PATH
, or my eval "$(pyenv init -)"
, so that I can do my docker exec
with everything loaded/sourced appropriately?
I would also consider Bash if Ash cannot do it.
Upvotes: 2
Views: 1297
Reputation: 295687
The file named by the environment variable ENV
is sourced when a POSIX-compliant shell (or bash in POSIX mode) is started in interactive mode, or when 1999 BSD ash is started under any conditions. If you want to support bash when in non-POSIX mode as well, you'll also want to set BASH_ENV
(which, like legacy BSD ash, is honored even for noninteractive shells).
Some versions of ash (including modern dash and busybox ash) follow the POSIX sh standard on this point, and consequently only honor ENV when invoked in interactive mode.
This means that with images following the 1999 BSD documentation for ash behavior, you can tell Docker to update the environment variable ENV
to point to a file which, when sourced by a shell interpreter, will run eval "$(pyenv init -)"
.
For images with newer or more-compliant versions of ash, consider using bash instead, and setting BASH_ENV
.
Upvotes: 3