问题描述
我已经尝试将环境变量放在客户机上的/ var / lib / boot2docker / profile文件中,然后重新启动它
I have tried to put my environment variable at /var/lib/boot2docker/profile file at guest machine, and restart it
然后我通过使用
使用
推荐答案
docker
守护进程源
/ var / lib / boot2docker / profile
开始之前。 HTTP_PROXY
变量将在 docker
守护程序环境中可用。通过 ssh
登录的用户将不会看到此变量。
The docker
daemon sources /var/lib/boot2docker/profile
before starting. The HTTP_PROXY
variable will be available in the docker
daemons environment. Users logging in via ssh
will not see this variable.
任何 /etc/profile.d/ * .sh
文件将在登录时加载到用户个人资料中正如您指出的,每次重新启动后,这将重新设置为基本映像。
Any /etc/profile.d/*.sh
files will be loaded into a users profile at login but as you pointed out, this is reset back to the base image after every reboot.
/ var / lib / boot2docker /
目录包含通过重新引导持久化的文件。
The /var/lib/boot2docker/
directory contains the files that are persisted over reboots. The bootlocal.sh
will be run at the end of startup. bootsync.sh
file will be run before docker.
编辑 / var / lib / boot2docker / bootsync.sh
包含
echo 'export HTTP_PROXY="http://whatever"' > /etc/profile.d/proxy.sh
然后,变量将可用于任何登录之后 docker
已经开始了。
Then the variable will be available for anything that logs in after docker
has started for the first time.
○ → docker-machine restart default-docker
...
○ → docker-machine ssh default-docker
...
docker@default-docker:~$ echo $HTTP_PROXY
http://whatever
这篇关于如何为boot2docker永久设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!