docker在线安装
(1)卸载旧版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
(2)需要的安装包
yum install -y yum-utils
(3)设置镜像的仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(4)更新yum软件包索引
yum makecache fast
(5)安装docker相关的源 docker-ce 社区 ee 企业版
yum install docker-ce docker-ce-cli containerd.io
(6)启动docker
systemctl start docker
(7)使用docker version 查看是否安装成功
docker version
(8)下载hello-world镜像-----------测试
docker run hello-world
(9)查看下载的这个 hello-world 镜像
{
“registry-mirrors”: [“https://p6y3p181.mirror.aliyuncs.com”]
}
~
(9)了解:卸载docker
# 1、依赖卸载
yum remove docker-ce docker-ce-cli containerd.io
# 2、删除资源
rm -rf /var/lib/docker
# /var/lib/docker docker的默认工作路径
docker 无网络离线安装
1、下载docker安装文件及对应版本https://download.docker.com/linux/static/stable/x86_64/
2、上传文件到服务器,并解压
tar -zxvf docker-20.10.2.tgz
3、 将解压出来的docker文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
4、 进入/etc/systemd/system/目录,并创建docker.service文件
cd /etc/systemd/system/
vim docker.service
5、赋值内容到上述文件,ip:192.168.8.127改成你自己的
[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 --selinux-enabled=false --insecure-registry=192.168.8.127
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
6、添加执行权限
chmod 777 /etc/systemd/system/docker.service
7、 重新加载配置文件
systemctl daemon-reload
8、启动
#启动
systemctl start docker
#设置开机自启
systemctl enable docker.service
9、查看docker的状态
systemctl status docker
10、配置镜像加速
打开docker的配置文件: /etc/docker/daemon.json文件:
{"registry-mirrors": ["http://hub-mirror.c.163.com"]}
11、 保存配置并重启docker
service docker restart