Docker在CentOS 7上的安装

前置条件:

OS:CentOS 7

[mars@bigdata-pro01 ~]$ uname -a
Linux bigdata-pro01.mars.com 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[mars@bigdata-pro01 ~]$ 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. 卸载老版本 (Uninstall old versions)

[mars@bigdata-pro01 ~]$ sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
Loaded plugins: fastestmirror, langpacks
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal

 

2. 安装 yum-utils 工具包 (which provides the yum-config-manager utility)

   并设置资源库(set up the stable repository)

[mars@bigdata-pro01 ~]$ sudo yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch           Version                    Repository    Size
================================================================================
Updating:
 yum-utils         noarch         1.1.31-54.el7_8            base         122 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total size: 122 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
icedtea-web-1.7.1-1.el7.x86_64 has missing requires of java-1.8.0-openjdk
jline-1.0-8.el7.noarch has missing requires of java >= ('0', '1.5', None)
  Updating   : yum-utils-1.1.31-54.el7_8.noarch                             1/2
  Cleanup    : yum-utils-1.1.31-50.el7.noarch                               2/2
  Verifying  : yum-utils-1.1.31-54.el7_8.noarch                             1/2
  Verifying  : yum-utils-1.1.31-50.el7.noarch                               2/2

Updated:
  yum-utils.noarch 0:1.1.31-54.el7_8

Complete!


[mars@bigdata-pro01 ~]$ sudo yum-config-manager \
> --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo   ## 默认是国外的镜像地址,我们使用国内阿里云的镜像地址,加快速度
Loaded plugins: 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


 

3. 更新yum索引  yum makecache fast 

[mars@bigdata-pro01 ~]$ yum makecache fast
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                                     | 3.6 kB     00:00
docker-ce-stable                                         | 3.5 kB     00:00
extras                                                   | 2.9 kB     00:00
updates                                                  | 2.9 kB     00:00
Metadata Cache Created

 

4. 安装Docker 引擎

sudo yum install docker-ce docker-ce-cli containerd.io
# ce 指社区版, ee是企业版
[mars@bigdata-pro01 ~]$ sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.4-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.4.4-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.5-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.5-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.5-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:20.10.5-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.5-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.5-3.el7.x86_64
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch   Version                   Repository        Size
================================================================================
Installing:
 containerd.io          x86_64 1.4.4-3.1.el7             docker-ce-stable  33 M
 docker-ce              x86_64 3:20.10.5-3.el7           docker-ce-stable  27 M
 docker-ce-cli          x86_64 1:20.10.5-3.el7           docker-ce-stable  33 M
Installing for dependencies:
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 docker-ce-rootless-extras
                        x86_64 20.10.5-3.el7             docker-ce-stable 9.1 M
 fuse-overlayfs         x86_64 0.7.2-6.el7_8             extras            54 k
 fuse3-libs             x86_64 3.6.1-4.el7               extras            82 k
 slirp4netns            x86_64 0.4.3-4.el7_8             extras            81 k

Transaction Summary
================================================================================
Install  3 Packages (+5 Dependent packages)

Total download size: 102 M
Installed size: 424 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): container-selinux-2.119.2-1.911c772.el7_8.noarch.rp |  40 kB   00:05
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.4.4-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.4.4-3.1.el7.x86_64.rpm is not installed
(2/8): containerd.io-1.4.4-3.1.el7.x86_64.rpm              |  33 MB   01:46
(3/8): docker-ce-cli-20.10.5-3.el7.x86_64.rpm              |  33 MB   01:09
(4/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm                   |  82 kB   00:00
(5/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm             |  54 kB   00:00
(6/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                |  81 kB   00:07
(7/8): docker-ce-rootless-extras-20.10.5-3.el7.x86_64.rpm  | 9.1 MB   00:17
(8/8): docker-ce-20.10.5-3.el7.x86_64.rpm                                                |  27 MB  00:03:22
----------------------------------------------------------------------------------------------------------------
Total                                                                           518 kB/s | 102 MB  00:03:22
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                           1/8
  Installing : containerd.io-1.4.4-3.1.el7.x86_64                                                           2/8
  Installing : slirp4netns-0.4.3-4.el7_8.x86_64                                                             3/8
  Installing : fuse3-libs-3.6.1-4.el7.x86_64                                                                4/8
  Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                          5/8
  Installing : 1:docker-ce-cli-20.10.5-3.el7.x86_64                                                         6/8
  Installing : docker-ce-rootless-extras-20.10.5-3.el7.x86_64                                               7/8
  Installing : 3:docker-ce-20.10.5-3.el7.x86_64                                                             8/8
  Verifying  : 1:docker-ce-cli-20.10.5-3.el7.x86_64                                                         1/8
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                                2/8
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                          3/8
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                             4/8
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                           5/8
  Verifying  : 3:docker-ce-20.10.5-3.el7.x86_64                                                             6/8
  Verifying  : docker-ce-rootless-extras-20.10.5-3.el7.x86_64                                               7/8
  Verifying  : containerd.io-1.4.4-3.1.el7.x86_64                                                           8/8

Installed:
  containerd.io.x86_64 0:1.4.4-3.1.el7  docker-ce.x86_64 3:20.10.5-3.el7  docker-ce-cli.x86_64 1:20.10.5-3.el7

Dependency Installed:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8      docker-ce-rootless-extras.x86_64 0:20.10.5-3.el7
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                   fuse3-libs.x86_64 0:3.6.1-4.el7
  slirp4netns.x86_64 0:0.4.3-4.el7_8

Complete!
View Code

上面默认安装的是最新版,也可以安装指定版本

a. 列出所有可用版本

[mars@bigdata-pro01 ~]$ yum list docker-ce --showduplicates | sort -r
[mars@bigdata-pro01 ~]$ yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.163.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
Installed Packages
 * extras: mirrors.163.com
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.5-3.el7                    @docker-ce-stable
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.0-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.15-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.14-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.13-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
 * base: mirrors.163.com
Available Packages
View Code

 

b. 指定版本安装

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

 

5. 启动Docker 

sudo systemctl start docker

6. 查看 Docker 是否安装成功

[mars@bigdata-pro01 ~]$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:33:55 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:32:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

 

7. 测试 hello-world 镜像

sudo docker run hello-world
[mars@bigdata-pro01 ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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/

 

8. 查看下载的hello-world 镜像 

[mars@bigdata-pro01 ~]$ sudo docker images
REPOSITORY    TAG       IMAGE ID       CREATED      SIZE
hello-world   latest    d1165f221234   5 days ago   13.3kB

 

9. 卸载Docker 

Uninstall the Docker Engine, CLI, and Containerd packages:

[mars@bigdata-pro01 ~]$ sudo yum remove docker-ce docker-ce-cli containerd.io

 


Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

 

You must delete any edited configuration files manually.

 

posted @ 2021-03-11 17:10  Justins999  阅读(167)  评论(0)    收藏  举报