基于Centos7搭建Docker

概念就不多说了,直接上手吧

环境:虚拟机装的Centos7,linux 4.19 内核,docker官方说至少3.8以上,建议3.10以上

1、root账户登录,查看内核版本如下

[root@ip ~]# uname -a
Linux 10-23-2-237 4.19.0-9.el7.ucloud.x86_64 #1 SMP Mon Sep 28 10:29:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@ip ~]# 
[root@ip ~]# 

2、把yum包更新到最新

[root@ip ~]# yum update -y

 

 3、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

[root@ip ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

 

4、设置yum源(选择其中一个)

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)

[root@ip~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

 

5、可以查看所有仓库中所有docker版本,并选择特定版本安装

[root@ip ~]# yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks, versionlock
Installed Packages
Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
....(省略)....
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            @docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 
Available Packages

 

6、安装Docker,命令:yum install docker-ce-版本号,我选的是docker-ce-18.03.1.ce,如下

[root@ip~]# yum install docker-ce-18.03.1.ce -y

 

7、启动Docker,命令:systemctl start docker,然后加入开机启动

[root@ip ~]# systemctl start docker
[root@ip ~]# systemctl enable  docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@10-23-2-237 ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 3
Server Version: 18.03.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.19.0-9.el7.ucloud.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.788GiB
Name: 10-23-2-237
ID: RBML:ZSDX:EBJW:4FKX:G2LX:77IU:VKOW:PEJN:LNWA:ITRT:NTXH:2GRH
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
Registry Mirrors:
http://hub-mirror.c.163.com/
Live Restore Enabled: false

 

8、修改docker镜像源

由于docker默认的源为国外官方源,下载速度较慢,所以在学习和使用中可改为国内的镜像源,这样速度会提高狠多。数据源可以参考下面的说明

方法一:

 编辑 /etc/docker/daemon.json

[root@ip ~]# vi /etc/docker/daemon.json

#添加如下网易镜像源
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

 

方法二:

 编辑/etc/sysconfig/docker,在OPTIONS变量后追加参数  --registry-mirror=镜像源地址

[root@ip ~]# vi /etc/sysconfig/docker
#编辑OPTIONS,添加中国科技大学的镜像源 
OPTIONS
='--selinux-enabled --log-driver=journald --registry mirror=https://docker.mirrors.ustc.edu.cn'

 

方法三:

 编辑/etc/default/docker,添加DOCKER_OPTS="--registry-mirror=镜像源"

[root@ip ~]# vi /etc/default/docker
#指定镜像源为阿里的镜像源
DOCKER_OPTS="--registry-mirror=https://pee6w651.mirror.aliyuncs.com"

 

Docker国内源说明:

Docker 官方中国区:

https://registry.docker-cn.com

网易:

http://hub-mirror.c.163.com

中国科技大学:

https://docker.mirrors.ustc.edu.cn

阿里云:

https://pee6w651.mirror.aliyuncs.com

 

posted @ 2020-11-26 20:49  小炮先生  阅读(239)  评论(0编辑  收藏  举报