环境
刚安装的好 Ubutnu 20.04 (一样的起点,安装步骤发生问题会少很多)
步骤
1、更换软件源
#备份原有软件源
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
#创建新的软件源文件
sudo vi /etc/apt/sources.list
#把下面这段复制到文件里
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#保存后执行下面的语句更新缓存和升级
sudo apt-get update
sudo apt-get upgrade
2、安装Docker
2.1安装
#执行这个一键安装
sudo wget -qO- https://get.docker.com | sh
#安装完成后执行下面语句检查安装是否成功
docker -version
2.2 添加官方GPG秘钥
#添加 Docker 的官方 GPG 密钥
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
#验证秘钥是否添加成功
sudo apt-key fingerprint 0EBFCD88
#如下输出就是正常(此处非执行命令)
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
2.3设置Docker仓库
#设置Docker仓库为稳定版
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"
如下结果就是正常的
2.4安装Docker引擎
sudo apt-get install docker-ce docker-ce-cli containerd.io
2.5测试安装是否成功
#测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:
sudo docker run hello-world
#输出信息
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
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/
到此安装就完成了