Ubuntu国内镜像Docker安装详细教程

暗香疏影 创作者

参考文献

Install Docker Engine on Ubuntu
如果你使用其他系统例如debian,请直接去官网查看,步骤稍微略有不同。

安装Docker

温馨提示:请记得先确认设置好Ubuntu的镜像源

懒惰的人可以直接通过以下命令安装+改源

1
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

升级

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

1
2
3
4
5
6
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

Add Docker’s official GPG key:

1
2
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Use the following command to set up the repository:

1
2
3
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装Docker Engine

Update the apt package index:

1
sudo apt-get update

Install Docker Engine, containerd, and Docker Compose.

1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

测试并安装没用的镜像:

1
sudo docker run hello-world

添加Docker image的国内镜像 Add registry

登录阿里云镜像加速 来获取你的镜像加速地址
只添加阿里源:

1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://example.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

全部源添加:
查看是否有这个文件:/etc/docker/daemon.json
没有直接sudo nano新增

1
2
3
4
5
6
7
{
"registry-mirrors": [
"https://example.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}

如果本身已有daemon.json,则应该如下示例

1
2
3
4
5
6
7
8
9
10
11
12
{
"log-opts": {
"max-size": "5m",
"max-file":"3"
},
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors":[
"https://qwe67a1n.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}

之后重新启动服务。

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

检查加速器是否生效
执行 $ docker info,(如果Docker还未配置用户,则需要用sudo) 如果从结果中看到了如下内容,说明配置成功。

1
2
Registry Mirrors:
https://hub-mirror.c.163.com/

安装portainer

Portainer CE安装

  • 标题: Ubuntu国内镜像Docker安装详细教程
  • 作者: 暗香疏影
  • 创建于 : 2023-02-18 00:00:00
  • 更新于 : 2023-02-18 00:00:00
  • 链接: https://blog.23ikr.com/2023/02/18/2023-02-18-docker-setup/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论