如何让/ etc / profile在Alpine / Docker中自动运行 [英] How to get /etc/profile to run automatically in Alpine / Docker

查看:2163
本文介绍了如何让/ etc / profile在Alpine / Docker中自动运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以交互方式启动Alpine Docker容器时,如何获得 / etc / profile 自动运行?我已经将一些别名添加到 aliases.sh 文件中,并将其放在 /etc/profile.d 中,但是我使用 docker run -it [my_container] sh 启动容器,我的别名不活动。我必须手动输入。 / etc / profile 从命令行每次。



是否有一些其他配置需要获得 / etc /个人资料在登录时运行?我也遇到使用〜/ .profile 文件的问题。任何见解都是感激的!



编辑:



根据VonC的答案,我拉扯了他的例子 ruby​​ container。这是我得到的:

  $ docker run --rm --name ruby​​ -it codeclimate / alpine-ruby:b42 
/#more /etc/profile.d/rubygems.sh
export PATH = $ PATH:/usr/lib/ruby/gems/2.0.0/bin
/#env
no_proxy = *。local,169.254 / 16
HOSTNAME = 6c7e93ebc5a1
SHLVL = 1
HOME = / root
TERM = xterm
PATH = / usr / local / sbin:/ usr / local / bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin
PWD = /
/#exit
/ pre>

尽管 /etc/profile.d/rubygems.sh 文件存在,但没有运行当我登录时,我的 PATH 环境变量没有被更新。我使用错误的 docker运行命令?还有别的东西吗有没有人在Docker上与Alpine搭配使用〜/ .profile /etc/profile.d / 谢谢!

解决方案

你还可以尝试在Dockerfile中a:

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

(假设当前用户是如果没有,请用完整的首页路径替换 / root



就是说,那些应该运行/etc/profile.d/xx.sh。

请参阅 codeclimate / docker-alpine-ruby 为例:

  COPY文件/ 

使用' 文件/ etc 包括一个 files / etc / profile。 d / ruby​​gems.sh 运行正常。






OP工程 Dockerfile ,有一个

  COPY aliases.sh /etc/profile.d/ 

但是默认shell是不是登录shell(sh -l),这意味着 个人资料文件(或 /etc/profile.d 中的文件)是来源



添加 sh -l <​​/ code>将工作:

  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


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 file and placed it in /etc/profile.d, but when I start the container using docker run -it [my_container] sh, my aliases aren't active. I have to manually type . /etc/profile from the command line each time.

Is there some other configuration necessary to get /etc/profile to run at login? I've also had problems with using a ~/.profile file. Any insight is appreciated!

EDIT:

Based on VonC's answer, I pulled and ran his example ruby container. Here is what I got:

$ docker run --rm --name ruby -it codeclimate/alpine-ruby:b42
/ # more /etc/profile.d/rubygems.sh
export PATH=$PATH:/usr/lib/ruby/gems/2.0.0/bin
/ # env
no_proxy=*.local, 169.254/16
HOSTNAME=6c7e93ebc5a1
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
/ # exit

Although the /etc/profile.d/rubygems.sh file exists, it is not being run when I login and my PATH environment variable is not being updated. Am I using the wrong docker run command? Is something else missing? Has anyone gotten ~/.profile or /etc/profile.d/ files to work with Alpine on Docker? Thanks!

解决方案

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

这篇关于如何让/ etc / profile在Alpine / Docker中自动运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆