How to get /etc/profile to run automatically in Alpine / Docker

后端 未结 3 1294
执念已碎
执念已碎 2020-12-13 04:52

How can I get /etc/profile to run automatically when starting an Alpine Docker container interactively? I have added some aliases to an aliases.sh

3条回答
  •  忘掉有多难
    2020-12-13 05:22

    You still can try in your Dockerfile a:

    RUN echo '\
            . /etc/profile ; \
        ' >> /root/.profile
    

    (assuming the current user is root. If not, replace /root with the full home path)

    That being said, those /etc/profile.d/xx.sh should run.
    See codeclimate/docker-alpine-ruby as an example:

    COPY files /
    

    With 'files/etc" including an files/etc/profile.d/rubygems.sh running just fine.


    In the OP project Dockerfile, there is a

    COPY aliases.sh /etc/profile.d/
    

    But the default shell is not a login shell (sh -l), which means profile files (or those in /etc/profile.d) are not sourced.

    Adding sh -l would work:

    docker@default:~$ docker run --rm --name ruby -it codeclimate/alpine-ruby:b42 sh -l
    87a58e26b744:/# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/ruby/gems/2.0.0/bin
    

提交回复
热议问题