问题
I know, with Ubuntu, you can set default values for environment variables in /etc/environment
; I do not see that file in Alpine linux. Is there a different location for setting system-wide defaults?
回答1:
It seems that /etc/profile
is the best place I could find. At least, some environment variables are set there:
export CHARSET=UTF-8
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PAGER=less
export PS1='\h:\w\$ '
umask 022
for script in /etc/profile.d/*.sh ; do
if [ -r $script ] ; then
. $script
fi
done
According to the contents of /etc/profile
, you can create a file with .sh
extension in /etc/profile.d/
and you have to pass --login
every time to load the env variables e.g docker exec -it container sh --login
.
回答2:
If you are talking about Alpine Docker image, then you can define those env variables inside Dockerfile like below. Here you don't need to pass --login
every time. These variables will be automatically available system wide globally.
FROM alpine
ENV GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXXXX \
COMPOSER_HOME=/home/deploy/.composer
Also you can define your alias, env etc inside /etc/profile and define a ENV
inside Dockerfile like below to source the profile automatically.
FROM alpine
ENV GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXXXX \
COMPOSER_HOME=/home/deploy/.composer
ENV ENV="/etc/profile"
来源:https://stackoverflow.com/questions/35325856/where-to-set-system-default-environment-variables-in-alpine-linux