Docker安装和启动
1 安装Docker
Docker安装建议在Ubuntu中安装,因为Docker是基于Ubuntu发布的。而且一般Docker出现的问题Ubuntu是最先更新或者打补丁的。在很多版本的CentOS中是不支持更新最新的一些补丁包的。
由于学习的环境都使用的是CentOS,因此将Docker安装到CentOS上。注意:这里建议安装在CentOS7以上版本,在CentOS的版本中,安装前需要安装其他很多的环境而且Docker很多补丁不支持更新。
1、yum包更新到最新
sudo yum update
2、安装需要的软件包,yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3、设置yum源为阿里云
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4、安装docker
sudo yum -y install docker-ce
5、安装后查看docker版本
docker -v
2 设置阿里云镜像加速器
1、注册阿里云镜像加速器,地址https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
2、获取Docker镜像加速器

创建配置文件
mkdir -p /etc/docker
vi /etc/docker/daemon.json
在改文件中输入如下内容
{
"registry-mirrors": ["https://xxx"]
}
3 Docker的启动与停止
systemctl命令是系统服务管理器指令
启动docker
systemctl start docker
停止docker
systemctl stop docker
重启docker
systemctl restart docker
查看docker状态
[root@localhost etc]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2020-04-06 13:21:28 CST; 11s ago
Docs: https://docs.docker.com
Main PID: 45694 (dockerd)
Tasks: 8
Memory: 42.3M
CGroup: /system.slice/docker.service
└─45694 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.081019934+08:00" lev...rpc
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.081028064+08:00" lev...rpc
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.081033304+08:00" lev...rpc
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.097589089+08:00" lev...t."
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.258831029+08:00" lev...ss"
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.371951568+08:00" lev...e."
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.383561452+08:00" lev...3.8
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.383666204+08:00" lev...on"
4月 06 13:21:28 localhost.localdomain dockerd[45694]: time="2020-04-06T13:21:28.394391415+08:00" lev...ck"
4月 06 13:21:28 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
设置docker开启自启动
[root@localhost etc]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
查看docker概要信息
docker info
查看docker帮助文档
docker --help
4 启动Docker错误
[root@localhost ~]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
解决方案:检查docker的配置文件daemon.json是否正确