Docker配置代理

        有时候我们在使用docker下载镜像的时候可能想要配置代理区下载那么本文就给大家分享一下docker怎么配置代理。

        假设你已经有了代理,那就编辑/usr/lib/systemd/system/docker.service

        在[Service]下添加

Environment="HTTP_PROXY=http://127.0.0.1:6666/"
Environment="HTTPS_PROXY=http://127.0.0.1:6666/"
Environment="NO_PROXY=localhost,127.0.0.1"

# HTTP_PROXY和HTTPS_PROXY填写代理地址
# NO_PROXY填写哪些地址不需要走代理
[root@bogon ~]# cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[Service]
Type=notify
Environment="HTTP_PROXY=http://127.0.0.1:6666/"
Environment="HTTPS_PROXY=http://127.0.0.1:6666/"
Environment="NO_PROXY=localhost,127.0.0.1"
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Older systemd versions default to a LimitNOFILE of 1024:1024, which is insufficient for many
# applications including dockerd itself and will be inherited. Raise the hard limit, while
# preserving the soft limit for select(2).
LimitNOFILE=1024:524288

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

接下来重启服务即可

sudo systemctl daemon-reload
sudo systemctl restart docker

### 如何配置飞牛系统的 Docker 代理设置 #### 创建或编辑 Docker 的守护程序配置文件 为了使 Docker 使用代理服务器,在 `/etc/docker` 路径下创建或修改 `daemon.json` 文件。此操作可以通过命令行完成。 ```bash sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "proxies": { "default": { "httpProxy": "http://your.proxy.server:port", "httpsProxy": "http://your.proxy.server:port", "noProxy": "localhost,127.0.0.1" } } } EOF ``` 上述代码中的 `"httpProxy"` 和 `"httpsProxy"` 应替换为实际使用的 HTTP 或 HTTPS 代理服务器地址和端口号;而 `"noProxy"` 列表定义了不需要经过代理访问的目标[^1]。 #### 更新并重启 Docker 守护进程 一旦完成了对 `daemon.json` 文件的编辑,就需要重新加载 systemd 配置,并重启 Docker 服务来应用更改: ```bash sudo systemctl daemon-reload sudo systemctl restart docker ``` 这一步骤确保新的代理设置生效[^2]。 #### 测试新配置的有效性 最后,尝试执行一些网络请求密集型的任务(比如拉取一个新的镜像),以此验证代理是否正常工作以及性能是否有改善。 对于在飞牛 NAS 系统中遇到的具体情况,如果官方提供的 Docker 功能已经内置了一定程度上的优化和支持,则可以直接利用这些特性简化代理配置过程。例如,某些 NAS 厂商可能会预设特定区域内的加速器作为默认选项之一,从而减少手动配置的需求[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值