一.查看系统内核和系统版本
[root@localhost /]# uname -r4.18.0-193.el8.x86_64
[root@localhost /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
[root@localhost /]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
二.安装和启动
[root@localhost /]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
[root@localhost /]# yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo #官方镜像源,下载慢不使用。指定国内的阿里云镜像地址
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里云docker镜像地址
#不卸载podman,安装docker会有冲突
#1.使用rpm -qa 查询podman是否安装
[root@localhost /]# rpm -qa podman
podman-1.6.4-10.module_el8.2.0+305+5e198a41.x86_64
#2.使用yum erase 程序名 buildah 卸载软件并删除依赖
[root@localhost /]# yum erase podman buildah
#docker-ce--表示社区版 ee表示企业版 containerd.io--io表示容器
[root@localhost /]# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
[root@localhost /]# systemctl start docker
[root@localhost /]# docker version
Client: Docker Engine - Community #docker版本
Version: 20.10.16
API version: 1.41
Go version: go1.17.10
Git commit: aa7e414
Built: Thu May 12 09:17:20 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.16
API version: 1.41 (minimum version 1.12)
Go version: go1.17.10
Git commit: f756502
Built: Thu May 12 09:15:41 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.4
GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc:
Version: 1.1.1
GitCommit: v1.1.1-0-g52de29d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@localhost /]# docker run hello-world
Unable to find image 'hello-world:latest' locally #未找到相关镜像
latest: Pulling from library/hello-world #远程拉取镜像
2db29710123e: Pull complete #签名信息
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
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/
三.查询hello-world镜像运行状态
[root@localhost /]# docker images
#镜像的仓库源 镜像的标签 镜像的ID 镜像的创建时间 镜像的大小
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 8 months ago 13.3kB
四.卸载docker
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
五.创建使用阿里云镜像加速
登录阿里云控制面板
可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
#创建docker文件夹
sudo mkdir -p /etc/docker
#创建/daemon.json文件来加速
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://wap7pgwu.mirror.aliyuncs.com"]
}
EOF
#systemctl 重新加载守护程序
sudo systemctl daemon-reload
#重启docker
sudo systemctl restart docker

