Centos 7.9 安装docker
环境查看
#系统内核
uname -r
3.10.0-1160.45.1.el7.x86_64
#系统版本
cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
安装
官方帮助文档:Install Docker Engine on CentOS | Docker Documentation
#1、卸载旧版本
yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
#2、设置安装包(本次安装采用仓库安装)
yum install -y yum-utils
已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.njupt.edu.cn * centos-sclo-rh: mirrors.njupt.edu.cn * centos-sclo-sclo: mirrors.njupt.edu.cn * extras: mirrors.huaweicloud.com * updates: mirrors.njupt.edu.cn 软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本 无须任何处理 #3、设置镜像仓库 官方命令:# 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
已加载插件:fastestmirror, langpacks adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo #4、快速更新yum源
yum makecache fast
#5、安装最新社区版docker引擎
yum install docker-ce docker-ce-cli containerd.io
#如果不想安装最新版本可指定版本安装命令如下: # yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
启动并测试
截止上面步骤docker已经安装完成接下来我们将启动服务并测试hello world
#6、启动docker
systemctl start docker
#7、查看docker版本信息
docker version
Client: Docker Engine - Community #客户端信息 Version: 20.10.11 API version: 1.41 Go version: go1.16.9 Git commit: dea9396 Built: Thu Nov 18 00:38:53 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community #服务端信息 Engine: Version: 20.10.11 API version: 1.41 (minimum version 1.12) Go version: go1.16.9 Git commit: 847da18 Built: Thu Nov 18 00:37:17 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.12 GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d runc: Version: 1.0.2 GitCommit: v1.0.2-0-g52b36a2 docker-init: Version: 0.19.0 GitCommit: de40ad0 #8、运行hello- world测试docker
docker run hello-world
Unable to find image 'hello-world:latest' locally #没有找到镜像 latest: Pulling from library/hello-world #拉取hello-world镜像 2db29710123e: Already exists Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685 Status: Downloaded newer image for hello-world:latest Hello from Docker! #此处打印说明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 镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB
了解:如何卸载docker
#1、Uninstall the Docker Engine, CLI, and Containerd packages: $ yum remove docker-ce docker-ce-cli containerd.io #2、Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes: $ rm -rf /var/lib/docker $ rm -rf /var/lib/containerd