Where to set system default environment variables in Alpine linux?

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.


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"