本文介绍两种docker安装方法:(一定要关闭防火墙)
安装前检查系统中是否已存在docker,
1、检查安装的docker
命令:yum list installed | grep docker #
2、卸载docker
命令:yum -y remove docker名称
3、删除镜像或者容器等等
rm -rf docker路径
第一种 在线安装:
1,安装
(1)、centos 6
命令:yum installhttps://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm(未验证)
命令:sudo yum install docker-io
(2)、centos 7
该系统的CentOS-Extras库中已带Docker,因此直接安装
命令:sudo yum install -y yum-utils device-mapper-persistent-data lvm2
命令:sudo yum-config-manager --add-repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
命令:sudo yum install docker-ce
2,启动
命令:service docker start #正常启动
命令:sudo chkconfig docker on #设置随机启动
3、其他
命令:docker version #查看版本
命令:docker info
第二种 离线安装:
1,下载docker安装包
下载地址:https://download.docker.com/linux/static/stable/x86_64/(我使用的是docker-18.06.1-ce.tgz版本)
2,在服务上解压文件:
tar -xzvf docker-18.06.1-ce.tgz
3,将解压后的文件:移动到/usr/bin/目录下面
执行命令:cp docker/* /usr/bin/
3,添加docker服务
添加文件:docker.service 在/etc/systemd/system/文件下。
执行命令:vim /etc/systemd/system/docker.service
文件内容拷贝一下内容(网上摘抄):
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --graph=/home/docker-images
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
4,添加文件可执行权限:
chmod +x /etc/systemd/system/docker.service
5,启动docker
systemctl daemon-reload
systemctl start docker #启动Docker
systemctl enable docker.service # 设置开机自启动
6,是否正常:
systemctl status docker #查看Docker状态
docker -v #查看Docker版本
7,docker 配置国内镜像文件
vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
重启:systemctl restart docker
以上,谢谢!