centos下docker的安装

centos下docker的安装

前言;docker呢作为现在非常火的一门技术,我也是刚刚接触这门课程不久,特此作出一些总结。视频的话可以参考B站的狂神说docker,希望可以给有兴趣的小伙伴提供一些帮助。

1、环境的查看

uname -r

#系统的内核要求是3.10以上的

[root@yingxiong ~]# uname -r
3.10.0-1062.el7.x86_64

2、可以ping外网

ping www.baidu.com

#修改网卡,可以连接外网,不然下载不了docker的一些依赖

[root@yingxiong ~]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=128 time=1159 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=3 ttl=128 time=24.9 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=128 time=23.7 ms

3、检查是否有旧的docker版本

yum list installed | grep docker

#因为我是新创建的centos,所以没有安装过docker(直接就可以做第五步),如果检查到有旧版本docker就要删除

[root@yingxiong ~]# yum list installed | grep docker

4、删除旧版本docker

yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine

#使用yum remove docker + 要删除的docker的形式,注意反斜杠是表示换行,因为我没有安装过docker包,所以显示没有

[root@yingxiong ~]# yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
Loaded plugins: fastestmirror
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

5、下载docker需要的依赖

yum install -y yum-utils

#下载好docker需要的依赖了

[root@yingxiong ~]# yum install -y yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.cqu.edu.cn
base                                                                                                                                                                                                                | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                              | 2.9 kB  00:00:00     
updates                                                                                                                                                                                                             | 2.9 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                                                                                                                                                   | 236 kB  00:00:00     
(2/4): updates/7/x86_64/primary_db                                                                                                                                                                                  | 8.0 MB  00:00:01     
(3/4): base/7/x86_64/primary_db                                                                                                                                                                                     | 6.1 MB  00:00:02     
base/7/x86_64/group_gz         FAILED                                          
http://mirrors.cqu.edu.cn/CentOS/7.9.2009/os/x86_64/repodata/a4e2b46586aa556c3b6f814dad5b16db5a669984d66b68e873586cd7c7253301-c7-x86_64-comps.xml.gz: [Errno 14] curl#7 - "Failed to connect to 2001:da8:c800:100:caca:18c::: Network is unreachable"
Trying other mirror.
(4/4): base/7/x86_64/group_gz                                                                                                                                                                                       | 153 kB  00:00:00     
Resolving Dependencies

6、设置docker仓库(这里使用的阿里云的仓库)-切记不要做yum源的配置,否则仓库设置会报错

 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#因为国外的比较慢,使用阿里云的比较好,后面还要配置一个镜像加速(这个我后面有教程的,简单四步)

[root@yingxiong ~]# yum-config-manager \
>     --add-repo \
>     http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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

7、下载最新的docker包(这里是可以指定docker的版本的)

yum install docker-ce docker-ce-cli containerd.io

#下载docker最新安装包时中间会输入两次y并且回车

[root@yingxiong ~]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.ustc.edu.cn
docker-ce-stable                                                                                                                                                                                                    | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                                                                                                                                                                         |   55 B  00:00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                                                                                                                         |  60 kB  00:00:00     
Resolving Dependencies
===========================================================================================================================================================================================================================================
Install  3 Packages (+13 Dependent packages)
Upgrade             (  1 Dependent package)

Total download size: 109 M
Is this ok [y/d/N]: y       #这里要输入y并且回车
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/17): checkpolicy-2.5-8.el7.x86_64.rpm   
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                      7.6 MB/s | 109 MB  00:00:14     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 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     #再次输入y并且回车
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction

8、启动docker服务(假如启动不成功,这说明docker没有下载成功)

systemctl start docker
[root@yingxiong ~]# systemctl start docker

9、查看docker的信息

docker info

#显示信息表示安装成功

[root@yingxiong ~]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc.)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.6
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1062.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 972.4MiB
 Name: yingxiong
 ID: T266:LOB2:GJCP:EHC7:N47E:6ZGV:VXUZ:Q3K2:UNBU:JBFD:JJIX:TMCS
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

10、使用hello-world测试

docker run hello-world
[root@yingxiong ~]# docker run hello-world

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/

11、docker的卸载(三步曲)

yum list installed | grep docker

#查看已经安装的docker

[root@yingxiong ~]# yum list installed | grep docker
containerd.io.x86_64                 1.4.4-3.1.el7                  @docker-ce-stable
docker-ce.x86_64                     3:20.10.6-3.el7                @docker-ce-stable
docker-ce-cli.x86_64                 1:20.10.6-3.el7                @docker-ce-stable
docker-ce-rootless-extras.x86_64     20.10.6-3.el7                  @docker-ce-stable
docker-scan-plugin.x86_64         

yum -y remove docker-ce docker-ce-cli containerd.io

#卸载下载的docker最新版,跟上面下载时是对应的哦

[root@yingxiong ~]# yum -y remove docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.4-3.1.el7 will be erased
---> Package docker-ce.x86_64 3:20.10.6-3.el7 will be erased
--> Processing Dependency: docker-ce for package: docker-ce-rootless-extras-20.10.6-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.6-3.el7 will be erased
--> Processing Dependency: docker-ce-cli for package: docker-scan-plugin-0.7.0-3.el7.x86_64
--> Running transaction check
---> Package docker-ce-rootless-extras.x86_64 0:20.10.6-3.el7 will be erased
---> Package docker-scan-plugin.x86_64 0:0.7.0-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================================================
 Package                                                           Arch                                           Version                                                  Repository                                                 Size
===========================================================================================================================================================================================================================================
Removing:
 containerd.io                                                     x86_64                                         1.4.4-3.1.el7                                            @docker-ce-stable                                         128 M
 docker-ce                                                         x86_64                                         3:20.10.6-3.el7                                          @docker-ce-stable                                         115 M
 docker-ce-cli                                                     x86_64                                         1:20.10.6-3.el7                                          @docker-ce-stable                                         156 M
Removing for dependencies:
 docker-ce-rootless-extras                                         x86_64                                         20.10.6-3.el7                                            @docker-ce-stable                                          24 M
 docker-scan-plugin                                                x86_64                                         0.7.0-3.el7                                              @docker-ce-stable                                          13 M

Transaction Summary
===========================================================================================================================================================================================================================================
Remove  3 Packages (+2 Dependent packages)

Installed size: 437 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 3:docker-ce-20.10.6-3.el7.x86_64                                                                                                                                                                                        1/5 
  Erasing    : docker-ce-rootless-extras-20.10.6-3.el7.x86_64                                                                                                                                                                          2/5 
  Erasing    : docker-scan-plugin-0.7.0-3.el7.x86_64                                                                                                                                                                                   3/5 
  Erasing    : 1:docker-ce-cli-20.10.6-3.el7.x86_64                                                                                                                                                                                    4/5 
  Erasing    : containerd.io-1.4.4-3.1.el7.x86_64                                                                                                                                                                                      5/5 
  Verifying  : containerd.io-1.4.4-3.1.el7.x86_64                                                                                                                                                                                      1/5 
  Verifying  : docker-ce-rootless-extras-20.10.6-3.el7.x86_64                                                                                                                                                                          2/5 
  Verifying  : 3:docker-ce-20.10.6-3.el7.x86_64                                                                                                                                                                                        3/5 
  Verifying  : docker-scan-plugin-0.7.0-3.el7.x86_64                                                                                                                                                                                   4/5 
  Verifying  : 1:docker-ce-cli-20.10.6-3.el7.x86_64                                                                                                                                                                                    5/5 

Removed:
  containerd.io.x86_64 0:1.4.4-3.1.el7                                           docker-ce.x86_64 3:20.10.6-3.el7                                           docker-ce-cli.x86_64 1:20.10.6-3.el7                                          

Dependency Removed:
  docker-ce-rootless-extras.x86_64 0:20.10.6-3.el7                                                                         docker-scan-plugin.x86_64 0:0.7.0-3.el7                                                                        

Complete!

#此时已经卸载包了,再删除它的镜像

rm -rf /var/lib/docker

#最后查看docker已经卸载,没有显示包

[root@yingxiong ~]# yum list installed | grep docker
[root@yingxiong ~]# 

因为是接触docker才不久,所以呢有什么错误欢迎有大佬可以指出!!!

你可能感兴趣的:(容器云,docker)