Docker 代理和权限问题

Docker代理设置

/etc/docker/daemon.json

sudo tee /etc/docker/daemon.json <<EOF
{
  "proxies": {
    "http-proxy": "http://10.0.114.195:7890",
    "https-proxy": "http://10.0.114.195:7890",
    "no-proxy": "localhost,127.0.0.1,::1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12"
  }
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

/usr/lib/systemd/system/docker.service

mkdir /usr/lib/systemd/system/docker.service.d/
cat << EOF > /usr/lib/systemd/system/docker.service.d/http-proxy.conf 
[Service]
Environment="HTTP_PROXY=http://10.0.114.195:7890"
Environment="HTTPS_PROXY=http://10.0.114.195:7890"
Environment="NO_PROXY=localhost,127.0.0.1,::1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12"
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Containerd代理设置

/usr/lib/systemd/system/containerd.service

mkdir /usr/lib/systemd/system/containerd.service.d/
cat << EOF > /usr/lib/systemd/system/containerd.service.d/http-proxy.conf 
[Service]
Environment="HTTP_PROXY=http://10.0.114.195:7890"
Environment="HTTPS_PROXY=http://10.0.114.195:7890"
Environment="NO_PROXY=localhost,127.0.0.1,::1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12"
EOF
sudo systemctl daemon-reload
sudo systemctl restart containerd

普通用户加入Docker容器组

假设你要将用户username添加到docker组,可以使用以下命令:

sudo usermod -aG docker username

这里的-aG选项表示将用户添加到指定的组中,而不影响其他组的成员关系。

使用env命令直接使用代理

alias podman='env HTTP_PROXY=http://10.0.114.195:7893 HTTPS_PROXY=http://10.0.114.195:7893 NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 podman'
env HTTP_PROXY=http://10.0.114.195:7893 HTTPS_PROXY=http://10.0.114.195:7893 NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 podman
posted @ 2024-11-27 15:48  Huihcuanf  阅读(6)  评论(0编辑  收藏  举报