地址:link
可以根据官方教程安装,本文以Ubuntu 18.04.1操作系统为例。
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
在安装docker engine之前务必要更新apt包索引,不然后面安装时候会找不到软件:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
没有可用的软件包 docker-ce,但是它被其它的软件包引用了。
这可能意味着这个缺失的软件包可能已被废弃,
或者只能在其他发布源中找到
E: 软件包 docker-ce 没有可安装候选
E: 无法定位软件包 docker-ce-cli
E: 无法定位软件包 containerd.io
E: 无法按照 glob ‘containerd.io’ 找到任何软件包
E: 无法按照正则表达式 containerd.io 找到任何软件包
安装Docker Engine and containerd
sudo apt-get update //必须再次更新apt索引包
sudo apt-get install docker-ce docker-ce-cli containerd.io
查看Docker 版本
docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:54:08 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:16 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
仅仅说明安装成功而已,下面进行启动docker和测试。
systemctl start docker
systemctl status docker
出现下面这个active状态说明docker已启动
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
Active: active (running) since Sat 2021-09-25 21:53:15 CST; 12h ago
Docs: https://docs.docker.com
Main PID: 16553 (dockerd)
Tasks: 30
CGroup: /system.slice/docker.service
└─16553 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/contai
sudo docker run hello-world
如果出现Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world docker: Get "https://registry-1.docker.io/v2/library/hello-world/manifests/sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4": EOF. See 'docker run --help'.
说明终端卡在Unable to find image ‘hello-world:latest’ locally位置 。
docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取镜像,出项这个问题的原因:docker服务器在国外,我们在国内无法正常拉取镜像,所以就需要我们为docker设置国内阿里云的镜像加速器
cd /etc/docker/
touch /etc/docker/daemon.json
vim daemon.json //编辑文件
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
} //写入到daemon.json中,最后wq保存
systemctl daemon-reload
systemctl restart docker
再次运行hello-world镜像
sudo docker run hello-world
如下面代码所示,表明运行成功。
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状态
systemctl status docker
Linux安装Docker的教程结束了,其他的使用方法和问题后期会补充。欢迎大家转载,收藏。