docker中设置proxy代理环境变量

目录

1.dockerfile中定义

2.对于已构建好的 Image

(1)传递永久环境变量

(2) 临时传递

3.对于已生成的容器:

(1)永久设定环境变量

(2)临时设定

1.dockerfile中定义

2.对于已构建好的 Image

有两种方式:

(1)传递永久环境变量

在启动的时候传入参数:

$ docker run --rm -it -e https_proxy="https://IP地址:端口" -e http_proxy="http://IP地址:端口" image名 

也可以将这写环境变量写成一个 .env文件然后使用 --env-file 去统一导入:

例如 Linux 下.env 文件:

http_proxy="http://IP地址:端口"
https_proxy="https://IP地址:端口"

执行命令:

$ docker run --rm -it --env-file .env image名

(2) 临时传递

(1)先运行Image

$ docker run -itd image名 bash

(2)在进入镜像后手动设置环境变量:

$ export http_proxy="http://IP地址:端口"
$ export https_proxy="https://IP地址:端口"


3.对于已生成的容器:

(1)永久设定环境变量

修改 /etc/profile 或者 ~/.bashrc 文件,在其中加入

export http_proxy=http://IP地址:端口
export https_proxy=http://IP地址:端口

(2)临时设定

在进入镜像后手动设置环境变量:

$export http_proxy=http://IP地址:端口
$export https_proxy=http://IP地址:端口

原文:Docker Container 代理配置一本通 - Anthony's Blog (anthonysun256.github.io)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值