I have tried to put my environment variable at /var/lib/boot2docker/profile file at guest machine, and restart it
我尝试将环境变量设置为/var/lib/boot2docker/profile文件,并重新启动它
export http_proxy=http://proxy:port
出口http_proxy = http://proxy:端口
then i open shell from my host machine (Windows 7) by using
然后我用我的主机(Windows 7)打开shell
docker-machine ssh default
docker-machine ssh违约
I can't find 'http_proxy' from my environment variable by using
我无法通过使用环境变量找到“http_proxy”
env
env
3 个解决方案
#1
1
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.
在启动之前,docker守护进程源/var/lib/boot2docker/profile。HTTP_PROXY变量将在docker守护进程环境中可用。通过ssh登录的用户将看不到这个变量。
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.
任何/etc/profile.d/*.sh文件将在登录时加载到用户配置文件中,但正如您所指出的,这将在每次重新启动后重新设置为基本映像。
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/目录包含在重新引导时持久化的文件。bootlocal。sh将在启动结束时运行。bootsync。sh文件将在docker之前运行。
Edit /var/lib/boot2docker/bootsync.sh
to include
编辑/var/lib/boot2docker / bootsync。sh包括
echo 'export HTTP_PROXY="http://whatever"' > /etc/profile.d/proxy.sh
Then the variable will be available for anything that logs in after docker
has started for the first time.
然后,对于docker第一次启动后登录的任何内容,该变量都是可用的。
○ → docker-machine restart default-docker
...
○ → docker-machine ssh default-docker
...
docker@default-docker:~$ echo $HTTP_PROXY
http://whatever
#2
1
When PHPdocker.io generates a docker-compose.yml file, it also puts in a section for the environment variables.
当PHPdocker。io生成一个docker-compose。在yml文件中,它还包含了环境变量部分。
tie-mysql:
image: mysql:5.7
container_name: tie-mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=db_name
- MYSQL_USER=db_user
- MYSQL_PASSWORD=db_password
It starts running Docker-compose from the Vagrantfile:
它开始运行docker - composer从流浪文件:
config.vm.provision "shell", run: "always",
inline: "cd /home/docker/tie/phpdocker && docker-compose up -d 1>&2"
and if you aren't using docker-compose you could also arrange to put an appropriate file (like @Matt's /etc/profile.d/proxy.sh
) into the virtual machine as it is being provisioned (with the config.vm.provision "shell"
), rather than manually adding it later.
如果您没有使用docker-compose,您也可以安排将一个适当的文件(如@Matt的/etc/profile.d/proxy.sh)放入虚拟机中,因为它正在被配置(与config.vm一起)。提供“shell”,而不是稍后手动添加。
#3
0
You can create a custom virtual machine with proxy configuration like this
您可以使用这样的代理配置创建一个自定义虚拟机
docker-machine create -d virtualbox --engine-env HTTP_PROXY=http://10.x.y.z:4951 --engine-env HTTPS_PROXY=https://10.x.y.z:4951 testbox
It will create a virtual machine with permanent proxy configuration.
它将创建一个具有永久代理配置的虚拟机。
#1
1
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.
在启动之前,docker守护进程源/var/lib/boot2docker/profile。HTTP_PROXY变量将在docker守护进程环境中可用。通过ssh登录的用户将看不到这个变量。
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.
任何/etc/profile.d/*.sh文件将在登录时加载到用户配置文件中,但正如您所指出的,这将在每次重新启动后重新设置为基本映像。
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/目录包含在重新引导时持久化的文件。bootlocal。sh将在启动结束时运行。bootsync。sh文件将在docker之前运行。
Edit /var/lib/boot2docker/bootsync.sh
to include
编辑/var/lib/boot2docker / bootsync。sh包括
echo 'export HTTP_PROXY="http://whatever"' > /etc/profile.d/proxy.sh
Then the variable will be available for anything that logs in after docker
has started for the first time.
然后,对于docker第一次启动后登录的任何内容,该变量都是可用的。
○ → docker-machine restart default-docker
...
○ → docker-machine ssh default-docker
...
docker@default-docker:~$ echo $HTTP_PROXY
http://whatever
#2
1
When PHPdocker.io generates a docker-compose.yml file, it also puts in a section for the environment variables.
当PHPdocker。io生成一个docker-compose。在yml文件中,它还包含了环境变量部分。
tie-mysql:
image: mysql:5.7
container_name: tie-mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=db_name
- MYSQL_USER=db_user
- MYSQL_PASSWORD=db_password
It starts running Docker-compose from the Vagrantfile:
它开始运行docker - composer从流浪文件:
config.vm.provision "shell", run: "always",
inline: "cd /home/docker/tie/phpdocker && docker-compose up -d 1>&2"
and if you aren't using docker-compose you could also arrange to put an appropriate file (like @Matt's /etc/profile.d/proxy.sh
) into the virtual machine as it is being provisioned (with the config.vm.provision "shell"
), rather than manually adding it later.
如果您没有使用docker-compose,您也可以安排将一个适当的文件(如@Matt的/etc/profile.d/proxy.sh)放入虚拟机中,因为它正在被配置(与config.vm一起)。提供“shell”,而不是稍后手动添加。
#3
0
You can create a custom virtual machine with proxy configuration like this
您可以使用这样的代理配置创建一个自定义虚拟机
docker-machine create -d virtualbox --engine-env HTTP_PROXY=http://10.x.y.z:4951 --engine-env HTTPS_PROXY=https://10.x.y.z:4951 testbox
It will create a virtual machine with permanent proxy configuration.
它将创建一个具有永久代理配置的虚拟机。