因为我的主机是win 但是我写代码一般是在虚拟机 Ubuntu或者子系统Wsl里面 导致局域网无法拉取Docker镜像呢~
- 局域网内的 ubuntu系统 需要 docker 拉取镜像
- 本机 ip:192.168.0.104
Docker安装
# 卸载老版本
sudo apt-get remove docker docker-engine docker.io containerd runc
# 设置 Docker 的apt存储库。 如果您使用 Ubuntu 衍生发行版,例如 Linux Mint,则可能需要使用UBUNTU_CODENAME而不是VERSION_CODENAME。
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
#安装Docker包 最新
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
#通过运行镜像来验证 Docker Engine 安装是否成功 hello-world。
sudo docker run hello-world
具体参考 官方文档
镜像拉取
一般的话 sudo docker run hello-world
是会拉取失败 超时
提示错误 大概如下
~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Retrying in 1 second
docker: error pulling image configuration: download failed after attempts=6: dial tcp xx.xx.xx.xx:443: i/o timeout.
See 'docker run --help'.
这个时候换加速源是没有用的 因为Docker被莫名禁止了 所以需要通过代理来运行
添加官方镜像
sudo vim /etc/docker/daemon.json
####内容如下
{
"registry-mirrors": ["https://hub.docker.com/"]
}
添加代理
#新建 proxy.conf 文件
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo cd /etc/systemd/system/docker.service.d
sudo touch proxy.conf
sudo vim /etc/systemd/system/docker.service.d/proxy.conf
####内容如下 检查自己的代理端口地址
[Service]
Environment="HTTP_PROXY=http://192.168.0.104:7890"
Environment="HTTPS_PROXY=http://192.168.0.104:7890"
重启 docker 服务
#加载变更的配置
systemctl daemon-reload
#重启docker服务
systemctl restart docker
查看配置是否生效
查看配置是否生效
systemctl show --property=Environment docker