0
点赞
收藏
分享

微信扫一扫

docker中设置proxy代理环境变量

李雨喵 2022-04-15 阅读 70
dockerproxy

目录

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)

举报

相关推荐

0 条评论