美文网首页初见
Centos安装Docker

Centos安装Docker

作者: 有内涵的Google | 来源:发表于2020-04-05 18:42 被阅读0次

Docker是什么

引用菜鸟教程的介绍: Docker 是一个开源的应用容器引擎,基于 Go 并遵从 Apache2.0 协议开源。

Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。

容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。

Docker 从 17.03 版本之后分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版)

Docker 支持的系统版本

  • 1.Centos7(64 bit)
  • 2.Centos8(64 bit)
  • 3.centos 6.5(64 bit)
  • 4.更高的版本

所以在Centos上安装Docker就有一些前提要求:

Docker只能运行在Centos7 上, 要求系统为64bit, 系统内核版本是3.10以上。

Docker 可以运行在Centos-6.5或者跟高版本的Centos上, 要求系统为64位的, 系统内核版本为2.6.32-431或者更高的版本.

一.检验当前的系统是否支持

  • 1.可以通过cat /etc/redhat-release查看当前的系统版本, 我的系统版本是Centos8.0
CentOS Linux release 8.0.1905 (Core) 
  • 2.通过uname -r 查看当前系统的内核版本
4.18.0-80.el8.x86_64

二.安装Docker

  • 1.为了确保万无一失, 我们将本机的yum包更新到最新yum -y update 这里可能会花费几分钟时间. 直到更新完毕.
  yum-4.2.7-7.el8_1.noarch                                                                                                                             

Installed:
  kernel-4.18.0-147.5.1.el8_1.x86_64                                  kernel-core-4.18.0-147.5.1.el8_1.x86_64                                         
  kernel-modules-4.18.0-147.5.1.el8_1.x86_64                          oddjob-mkhomedir-0.34.4-7.el8.x86_64                                            
  conmon-2:2.0.6-1.module_el8.1.0+272+3e64ee36.x86_64                 gnome-shell-extension-horizontal-workspaces-3.32.1-10.el8.noarch                
  oddjob-0.34.4-7.el8.x86_64                                          podman-manpages-1.6.4-2.module_el8.1.0+272+3e64ee36.noarch                      
  xorg-x11-drv-fbdev-0.5.0-2.el8.x86_64                               xorg-x11-drv-vesa-2.4.0-3.el8.x86_64                                            
  centos-gpg-keys-8.1-1.1911.0.9.el8.noarch                           centos-repos-8.1-1.1911.0.9.el8.x86_64                                          
  grub2-tools-efi-1:2.02-78.el8_1.1.x86_64                            libssh-config-0.9.0-4.el8.noarch                                                
  libvarlink-18-3.el8.x86_64                                          mozjs60-60.9.0-3.el8.x86_64                                                     
  python3-pip-wheel-9.0.3-15.el8.noarch                               python3-setuptools-wheel-39.2.0-5.el8.noarch                                    

Complete!
[root@localhost /]# 
  • 2.安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
yum install -y yum-utils device-mapper-persistent-data lvm2
  • 3.设置稳定的仓库源。
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

设置完成后,可以使用ls /etc/yum.repos.d/ 查看, 就会在目录下多一个下载的docker.ce.repo源.

  • 4.可以查看仓库的所有的docker版本, 并选择特定的版本安装.
[root@localhost yum.repos.d]# yum list docker-ce --showduplicates | sort -r
Failed to set locale, defaulting to C.UTF-8
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
......

使用下面二选一的命令即可:

yum install docker-ce # 由于repo默认只开启stable仓库, 所以使用这个命令就会安装最新的稳定版
yum install docker-ce-<VERSION_STRING> 

如果遇到以下的报错信息:

Error: 
 Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

是因为Centos8默认使用pondman代替docker, 所以提示我们需要containerd.io大于1.2.2-3, 所以我们可以安装低版本的docker , 如果不想安装低版本的docker, 那么我们就更新安装containerd.io.

[root@localhost ~]#  wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@localhost ~]#  yum install -y  containerd.io-1.2.6-3.3.el7.x86_64.rpm

等待安装完毕后, 再次运行yum install docker-ce出现以下信息说明安装成功了.

Running transaction
  Preparing        :                                                                                                                               1/1 
  Installing       : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                          1/3 
  Running scriptlet: docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                          1/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                  2/3 
  Installing       : libcgroup-0.41-19.el8.x86_64                                                                                                  2/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                  2/3 
  Installing       : docker-ce-3:19.03.8-3.el7.x86_64                                                                                              3/3 
  Running scriptlet: docker-ce-3:19.03.8-3.el7.x86_64                                                                                              3/3 
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                                                                  1/3 
  Verifying        : docker-ce-3:19.03.8-3.el7.x86_64                                                                                              2/3 
  Verifying        : docker-ce-cli-1:19.03.8-3.el7.x86_64                                                                                          3/3 

Installed:
  docker-ce-3:19.03.8-3.el7.x86_64                  libcgroup-0.41-19.el8.x86_64                  docker-ce-cli-1:19.03.8-3.el7.x86_64                 

Complete!

三.检查是否安装成功

  • 1.可以查看docker的版本号docker -v
[root@localhost Desktop]# docker -v
Docker version 19.03.8, build afacb8b
  • 2.运行hello-world容器
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker run hello-world
[root@localhost Desktop]# docker run helloworld
Unable to find image 'helloworld:latest' locally
docker: Error response from daemon: pull access denied for helloworld, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
[root@localhost Desktop]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
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, 可以配置国内镜像

  • 1.在etc/docker/下找到daemon.json文件, 如果没有就创建这个文件.写入一下内容
{"registry-mirrors":["https://registry.docker-cn.com"]}
  • 2.重新启动服务
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl restart docker

相关文章

网友评论

    本文标题:Centos安装Docker

    本文链接:https://www.haomeiwen.com/subject/idhpphtx.html