Docker 安装及镜像加速器配置

本文档详细介绍了如何在Ubuntu 18.04操作系统上安装Docker,包括更新系统、添加GPG证书、设置软件源、安装Docker-CE以及启用Docker服务。此外,还讲解了配置Docker镜像加速器的步骤,以提高镜像下载速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

本次实验使用的操作系统镜像为 ubuntu-18.04.2-desktop

第一步 安装操作系统

1.1 软件下载

使用官方提供的 Ubuntu 18.04.2 Desktop 镜像,下载地址:https://ubuntu.com/download

1.2 软件安装

此步骤省略

1.3 登录后输入以下命令,切入到 root 用户

rsecc@rsecc:~$ sudo -i
[sudo] password for rsecc:

第二步 Docker 安装

2.1 安装必要的系统工具

root@rsecc:~# apt-get update
root@rsecc:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common

2.2 安装 GPG 证书

root@rsecc:~# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -

2.3 写入软件源信息

root@rsecc:~# add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

2.4 更新并安装 Docker-CE

root@rsecc:~# apt-get -y update
root@rsecc:~# apt-get -y install docker-ce

2.5 启动 docker 并设置开机自启

root@rsecc:~# systemctl start docker
root@rsecc:~# systemctl enable docker

2.6 测试

root@rsecc:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

第三章 配置 Docker 镜像加速器

3.1 修改或创建 daemon 配置文件 /etc/docker/daemon.json 来使用加速器

root@rsecc:~# mkdir -p /etc/docker
root@rsecc:~# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF

3.2 重启 daemon 和 Docker

root@rsecc:~# systemctl daemon-reload
root@rsecc:~# systemctl restart docker

3.3 检查加速器是否生效

root@rsecc:~# docker info
……省略……
Registry Mirrors:
  https://registry.docker-cn.com/
 Live Restore Enabled: false

附录

Docker 镜像加速列表

Docker 中国官方镜像:https://registry.docker-cn.com

科大镜像站:https://docker.mirrors.ustc.edu.cn

阿里云:https://<your_code>.mirror.aliyuncs.com [需要注册,获取专属的镜像加速链接]

七牛云:https://reg-mirror.qiniu.com

华为云:https://<your_code>.mirror.swr.myhuaweicloud.com [需要注册,获取专属的镜像加速链接]

腾讯云:https://mirror.ccs.tencentyun.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值