centos7安裝docker


環境:

centos7.8  內核3.10

[root@centos7 ~]# uname -a
Linux centos7 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@centos7 ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

昨天剛在虛擬機里裝的centos7,環境很干凈,安裝教程:VMware安裝Centos7超詳細教程

找官方文檔,避免每次安裝要搜別人博客

 

 

 

 

 

 

 

 

 

   終於找到了:https://docs.docker.com/engine/install/centos/

下面按照官方文檔操作就行

 1.Uninstall old versions 卸載老版本

[root@centos7 ~]# 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.安裝方法,推薦通過docker倉庫安裝

2.1 SET UP THE REPOSITORY 設置倉庫

[root@centos7 ~]# yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
base                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                               | 2.9 kB  00:00:00     
updates                                                                                                              | 2.9 kB  00:00:00     
Package yum-utils-1.1.31-53.el7.noarch already installed and latest version
Nothing to do
[root@centos7 ~]# yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

 

 

2.2 INSTALL DOCKER ENGINE 安裝docker引擎

2.2.1 Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

安裝最新版docker按這步操作就行,需要指定版本,看下一步2.2.2(我是裝的最新版)

[root@centos7 ~]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
docker-ce-stable                                                                                                          | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/updateinfo                                                                                 |   55 B  00:00:00     
(2/2): docker-ce-stable/x86_64/primary_db                                                                                 |  41 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.2.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.8-3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.8-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.1-1.c57a6f9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================
 Package                             Arch                     Version                                   Repository                          Size
=================================================================================================================================================
Installing:
 containerd.io                       x86_64                   1.2.13-3.2.el7                            docker-ce-stable                    25 M
 docker-ce                           x86_64                   3:19.03.8-3.el7                           docker-ce-stable                    25 M
 docker-ce-cli                       x86_64                   1:19.03.8-3.el7                           docker-ce-stable                    40 M
Installing for dependencies:
 container-selinux                   noarch                   2:2.119.1-1.c57a6f9.el7                   extras                              40 k

Transaction Summary
=================================================================================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 90 M
Installed size: 371 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm is not installed
(1/4): container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm                                                                 |  40 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for containerd.io-1.2.13-3.2.el7.x86_64.rpm is not installed
(2/4): containerd.io-1.2.13-3.2.el7.x86_64.rpm                                                                            |  25 MB  00:00:20     
(3/4): docker-ce-19.03.8-3.el7.x86_64.rpm                                                                                 |  25 MB  00:00:20     
(4/4): docker-ce-cli-19.03.8-3.el7.x86_64.rpm                                                                             |  40 MB  00:00:31     
-------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                            1.7 MB/s |  90 MB  00:00:52     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
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.1-1.c57a6f9.el7.noarch                                                                              1/4 
  Installing : containerd.io-1.2.13-3.2.el7.x86_64                                                                                           2/4 
  Installing : 1:docker-ce-cli-19.03.8-3.el7.x86_64                                                                                          3/4 
  Installing : 3:docker-ce-19.03.8-3.el7.x86_64                                                                                              4/4 
  Verifying  : 2:container-selinux-2.119.1-1.c57a6f9.el7.noarch                                                                              1/4 
  Verifying  : containerd.io-1.2.13-3.2.el7.x86_64                                                                                           2/4 
  Verifying  : 1:docker-ce-cli-19.03.8-3.el7.x86_64                                                                                          3/4 
  Verifying  : 3:docker-ce-19.03.8-3.el7.x86_64                                                                                              4/4 

Installed:
  containerd.io.x86_64 0:1.2.13-3.2.el7             docker-ce.x86_64 3:19.03.8-3.el7             docker-ce-cli.x86_64 1:19.03.8-3.el7            

Dependency Installed:
  container-selinux.noarch 2:2.119.1-1.c57a6f9.el7                                                                                               

Complete!
加-y更省事,省的過程中敲了
yum install -y docker-ce docker-ce-cli containerd.io

2.2.2 To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

這是安裝指定版本的,首先列出可用的版本有哪些,然后選擇並安裝,如下圖

 2.2.3 Start Docker 啟動docker

[root@centos7 ~]# systemctl start docker

2.2.4 Verify that Docker Engine is installed correctly by running the hello-world image. 運行hello-world,驗證docker是否安裝成功

[root@centos7 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
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/

至此,docker安裝完成

查看一下docker版本:docker version

[root@centos7 ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:25:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

查看執行過的docker進程:docker ps --all

[root@centos7 ~]# docker ps --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
48250840ce55        hello-world         "/hello"            5 seconds ago       Exited (0) 4 seconds ago                           wonderful_goldberg


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM