Docker傻瓜式的安装

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/jdk_wangtaida/article/details/95933757

前言:

上篇文章讲了docker的几个基本概念,这篇文章讲怎么在Linux下安装Docker的过程。

正文:

有yum命令和脚本安装两种方式,这里主要讲yum安装的方式

一、安装前准备

1.系统要求

Docker CE支持64位版本CenOS7,并且要求内核版本不低于3.10

查看内核版本的指令

[root@localhost 桌面]# uname -r
3.10.0-327.el7.x86_64

2.如果原系统里安装着旧版本,先卸载旧版本。旧版本的Docker称为docker或者docker-engine,使用以下命令卸载旧版本:

[root@localhost 桌面]# sudo yum remove docker

二、安装

1.安装的指令


[root@localhost 桌面]# yum install docker-ce

如果出现下面的提示:没有可用软件包,这个时候需要安装必要的软件依赖及更新增加docker-ce yum源

已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/4): extras/7/x86_64/primary_db                          | 205 kB   00:00     
(2/4): base/7/x86_64/group_gz                              | 166 kB   00:00     
(3/4): base/7/x86_64/primary_db                            | 6.0 MB   00:01     
(4/4): updates/7/x86_64/primary_db                         | 6.5 MB   00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
没有可用软件包 docker-ce。
错误:无须任何处理

安装docker-ce yum源的指令有两步:

[root@localhost 桌面]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
rpm.x86_64 0:4.11.3-35.el7                                                    
  rpm-build-libs.x86_64 0:4.11.3-35.el7                                         
  rpm-libs.x86_64 0:4.11.3-35.el7                                               
  rpm-python.x86_64 0:4.11.3-35.el7                                             
  yum.noarch 0:3.4.3-161.el7.centos                                             

完毕!
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker.ce.repo

 此处可能会报错 (原因是国内访问不到docker官方镜像的缘故),解决办法就是换成阿里云的地址

[root@localhost 桌面]# $sudo 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

2.再次执行yum install docker-ce 指令就不会报错啦,连输入两次Y,出现完毕就docker安装成功

事务概要
=================================================================================
安装  1 软件包 (+ 3 依赖软件包)
升级           ( 14 依赖软件包)

总计:69 M
总下载量:69 M
Is this ok [y/d/N]: y


总计                                                7.5 MB/s |  69 MB  00:09     
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "Docker Release (CE rpm) <[email protected]>"
 指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
是否继续?[y/N]:y


作为依赖被升级:
  libseccomp.x86_64 0:2.3.1-3.el7                                                
  libselinux.x86_64 0:2.5-14.1.el7                                               
  libselinux-devel.x86_64 0:2.5-14.1.el7                                         
  libselinux-python.x86_64 0:2.5-14.1.el7                                        
  libselinux-utils.x86_64 0:2.5-14.1.el7                                         
  libsemanage.x86_64 0:2.5-14.el7                                                
  libsemanage-python.x86_64 0:2.5-14.el7                                         
  libsepol.x86_64 0:2.5-10.el7                                                   
  libsepol-devel.x86_64 0:2.5-10.el7                                             
  policycoreutils.x86_64 0:2.5-29.el7_6.1                                        
  policycoreutils-python.x86_64 0:2.5-29.el7_6.1                                 
  selinux-policy.noarch 0:3.13.1-229.el7_6.12                                    
  selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.12                           
  setools-libs.x86_64 0:3.3.8-4.el7                                              

完毕!

3.启动docker的指令和开启启动

[root@localhost 桌面]# systemctl start docker
[root@localhost 桌面]# systemctl enable docker

 4.查看docker的安装信息

[root@localhost 桌面]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.7
Storage Driver: devicemapper
 Pool Name: docker-253:0-941162-pool
 Pool Blocksize: 65.54kB
 Base Device Size: 10.74GB
 Backing Filesystem: xfs
 Udev Sync Supported: true
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 11.8MB
 Data Space Total: 107.4GB
 Data Space Available: 11.66GB
 Metadata Space Used: 581.6kB
 Metadata Space Total: 2.147GB
 Metadata Space Available: 2.147GB
 Thin Pool Minimum Free Space: 10.74GB
 Deferred Removal Enabled: true
 Deferred Deletion Enabled: true
 Deferred Deleted Device Count: 0
 Library Version: 1.02.149-RHEL7 (2018-07-20)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.782GiB
Name: localhost.localdomain
ID: 5DKJ:SW65:PU6Q:MHYY:NNXQ:RPOL:KWBB:GGG5:M7C6:XUFU:MGUF:EMWA
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

 5.测试docker是否安装正确

docker run hello-world  #启动一个基于hello-world镜像的容器

若输出以下信息,则说明安装成功

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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的安装起来还是比较简单的,但是在理解上可能需要下点功夫。

我是阿达,一名喜欢分享知识的程序员,时不时的也会荒腔走板的聊一聊电影、电视剧、音乐、漫画,这里已经有310位小伙伴在等你们啦,感兴趣的就赶紧来点击关注我把,哪里有不明白或有不同观点的地方欢迎留言。

猜你喜欢

转载自blog.csdn.net/jdk_wangtaida/article/details/95933757