安装Docker
环境准备
1、需要linux基础知识
2、CentOS7
3、我们使用Xshell连接远程服务器进行操作
环境查看
# 系统内核是3.10以上
[root@localhost ~]# uname -r
3.10.0-1160.42.2.el7.x86_64
# 系统版本
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
安装
帮助文档:
1.卸载旧版
$sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.需要的安装包
$sudo yum install -y yum-utils
3.设置镜像的仓库
$sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo # 默认是国外的镜像地址
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 推荐使用国内的阿里云镜像地址
4.更新软件包索引
$sudo yum makecache fast
5.安装docker, docker-ce 社区版 docker-ee 企业版
$sudo yum install docker-ce docker-ce-cli containerd.io # 官方推荐使用社区版
# 可以列出和分类docker版本
$ yum list docker-ce --showduplicates | sort -r
# 安装指定版本的docker
$sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
# 6. 启动docker
$sudo systemctl start docker
# 7. 判断启动成功
# docker version
[root@localhost ~]# 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:55:49 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:54:13 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
# 8.hello-word
$sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/
# 9.查看一下下载的这个hello-world镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 2 weeks ago 448MB
ubuntu latest ba6acccedd29 2 months ago 72.8MB
hello-world latest feb5d9fea6a5 3 months ago 13.3kB
mariadb latest 6b01262bc780 4 months ago 409MB
vulhub/discuz x3.4 5a979b3474c5 4 years ago 441MB
了解:卸载docker
# 1.卸载依赖
$sudo yum remove docker-ce docker-ce-cli containerd.io
# 2.删除资源
$sudo rm -rf /var/lib/docker # dockers的默认工作路径
$sudo rm -rf /var/lib/containerd