容器二:centos7下部署docker环境

前言

命令集合
参考地址:https://www.runoob.com/docker/centos-docker-install.html

实际操作

准备内核

#查看内核版本
$ uname -r
     3.10.0-957.el7.x86_64
#使用AUFS作为存储驱动,先确认是否启用该功能
$ ls -l /sys/class/misc/device-mapper
     lrwxrwxrwx. 1 root root 0 Jun 17 17:57 /sys/class/misc/device-mapper -> ../../devices/virtual/misc/device-mapper
#如果没有检测到Device Mapper,需要安装device-mapper软件包
$ sudo yum install -y device-mapper
#然后重新加载dm_mod内核模块
$ sudo modprobe dm_mod

#CentOS7能上外网
#切换admin用户  $ su- 
#yum( Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器
#yum [options] [command] [package ...]
#GCC:GNU Compiler Collection(GUN 编译器集合),它可以编译C、C++、JAV、Fortran、Pascal、Object-C、Ada等语言
$ yum -y install gcc
$ yum -y install gcc-c++
yum会自动查找软件的相关依赖包,自动下载安装,全过程轻松愉快

安装部署(去$符号)


#卸载旧版本,如yum报告未安装任何这些软件包,无视
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
#安装依赖包(设置仓库)
yum install -y yum-utils device-mapper-persistent-data lvm2
#设置稳定的仓库(官方)
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
或(阿里云,推荐)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#更新yum软件包索引(接下来模糊,所以分开写)
yum makecache fast

Loaded plugins: fastestmirror, langpacks
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     
docker-ce-stable                                                                  | 3.5 kB  00:00:00     
extras                                                                            | 2.9 kB  00:00:00     
updates                                                                           | 2.9 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/updateinfo                                         |   55 B  00:00:02     
(2/2): docker-ce-stable/x86_64/primary_db                                         |  45 kB  00:00:02     
Metadata Cache Created

#1、安装最新的 Docker Engine-Community,更新yum软件包索引

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

#2、指定版本安装:

#列出并排序您存储库中可用的版本
$ yum list docker-ce --showduplicates | sort -r
#$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

这里使用3:19.03.7-3.el7
yum install docker-ce-3:19.03.7-3.el7 docker-ce-cli-3:19.03.7-3.el7 containerd.io

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.cqu.edu.cn
No package docker-ce-3:19.03.7-3.el7 available.
No package docker-ce-cli-3:19.03.7-3.el7 available.
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
--> 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
Installing for dependencies:
 container-selinux         noarch         2:2.119.1-1.c57a6f9.el7         extras                    40 kzao

Transaction Summary
=========================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 25 M
Installed size: 97 M
Is this ok [y/d/N]: 

操作: y 继续操作:y

Downloading packages:
(1/2): 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/2): containerd.io-1.2.13-3.2.el7.x86_64.rpm                                    |  25 MB  00:00:59     
---------------------------------------------------------------------------------------------------------
Total                                                                    438 kB/s |  25 MB  00:00:59     
Retrieving key from https://mirrors.aliyun.com/docker-ce/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://mirrors.aliyun.com/docker-ce/linux/centos/gpg
....
Installed:
  containerd.io.x86_64 0:1.2.13-3.2.el7                                                                  

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

Complete!

启动docker

sudo systemctl start docker
Failed to start docker.service: Unit not found
#解决
yum update(慎重使用,会更新所有)
yum -y update 升级所有包,同时也升级软件和系统内核
yum -y upgrade 只升级所有包,不升级软件和系统内核
重启系统 (立即关启系统:shutdown -r now)
安装最新的版本
yum -y install docker-ce
  
  Installed:
      docker-ce.x86_64 3:19.03.12-3.el7                                                                                                                                                                              
  Dependency Installed:
      docker-ce-cli.x86_64 1:19.03.12-3.el7 
再启动
#通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 
sudo docker run hello-world
docker version

Hello from Docker! 安装完毕

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