Ubuntu虚拟机(WSL) 安装Docker

因为我的主机是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

运行sudo docker run hello-world

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值