Where to set system default environment variables in Alpine linux?

让人想犯罪 __ 提交于 2020-05-09 20:51:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!