一、安装docker

从阿里云yum源安装依赖库

snippet.bash
[root@localhost software]# yum install libseccomp.x86_64
[root@localhost software]# yum install container-selinux.noarch

下载组件

https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

安装组件

snippet.bash
[root@localhost software]# rpm -i ./containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@localhost software]# rpm -i ./docker-ce-cli-19.03.9-3.el7.x86_64.rpm
[root@localhost software]# rpm -i ./docker-ce-19.03.9-3.el7.x86_64.rpm

二、启动docker服务

snippet.bash
[root@localhost software]# systemctl start docker

三、安装CentOS示例

搜索镜像

snippet.bash
[root@localhost software]# docker search CentOS
NAME         DESCRIPTION                          STARS     OFFICIAL   AUTOMATED
centos       The official build of CentOS.        6029       [OK]                
ansible/centos7-ansible   Ansible on Centos7      129        [OK]
……

安装CentOS镜像

CentOS镜像获取地址:https://hub.docker.com/_/centos?tab=tags

snippet.bash
[root@localhost software]# docker pull centos:centos7
centos7: Pulling from library/centos
524b0c1e57f8: Pull complete 
……

查询已安装的镜像

snippet.bash
[root@localhost software]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              centos7             b5b4d78bc90c        4 weeks ago         203MB

run镜像

snippet.bash
[root@localhost software]# docker run -itd --name centos-node1 centos:centos7
4c619a88c1eb3a546e53858826a71daf80a8fc41fae17d53c67c80f671e71f2a

查询run的镜像

snippet.bash
[root@localhost software]# docker ps
CONTAINER ID  IMAGE           COMMAND      CREATED         STATUS        PORTS   NAMES
4c619a88c1eb  centos:centos7  "/bin/bash"  7 seconds ago   Up 7 seconds          centos-node1

执行命令

通过 exec 命令对指定的容器执行 bash:

snippet.bash
[root@localhost software]# docker exec -it centos-node1 /bin/bash