一.安装docker
1.检查内核,低于3.10,执行升级命令
检查内核
uname -r
yum update -y
升级成功
2.安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
3.设置yum源(选择其中一个),推荐阿里云,速度快一点
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.查看仓库中所有docker版本,选择一个安装
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.03.1.ce
或直接安装最新版
yum install -y docker-ce docker-ce-cli containerd.io
5.启动docker,设为开机自启动
systemctl start docker
6.查看docker版本号
docker version
[root@dev ~]# docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:56:24 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:48 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.8
GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2
runc:
Version: 1.0.0
GitCommit: v1.0.0-0-g84113ee
docker-init:
Version: 0.19.0
GitCommit: de40ad0
如果没有Server: Docker Engine - Community说明没有启动
service docker start
7.测试是否安装成功并运行
docker run hello-world
[root@dev ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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
1、卸载Docker包
yum remove docker-ce
2、删除所有图像,容器和卷
rm -rf /var/lib/docker
- 主机上的图像,容器,卷或自定义配置文件不会自动删除。
docker run 指令中加入 --restart=always 就行。
sudo docker run --restart=always …
如果创建时未指定 --restart=always ,可通过update 命令设置
docker update --restart=always xxx