在线安装docker
-
yum 包更新到最新【可选】
yum update -
安装需要的软件包,yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2 -
设置yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -
将服务器上的软件包信息先在本地缓存,以提高搜索安装软件的速度【可选】
(可使用 yum clean all 命令清除缓存)
yum makecache fast -
安装 docker。-y 是自动选择 yes,不用再手动输入
yum -y install docker-ce -
查看docker版本,验证是否安装成功
docker -v
离线安装docker
-
将安装包 docker-19.03.1.tgz 上传到 /usr/local 目录下
-
解压
tar -xvf docker-19.03.1.tgz -
解压出来是一个docker文件夹,将docker目录下的所有内容复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/ -
将docker注册为服务
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
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
- 为文件添加可执行权限
chmod +x /etc/systemd/system/docker.service - 启动docker
systemctl daemon-reload #重载unit配置文件
systemctl start docker #启动Docker
systemctl enable docker.service #设置开机自启,可选 - 验证docker是否启动成功
systemctl status docker #查看docker状态
docker -v #查看docker版本
在线安装的卸载方法
1.查询docker安装过的包:
yum list installed | grep docker
2.删除安装包:(-y表示出现选择默认输入y,不用再手动输入)
yum -y remove 安装包名称
3.删除镜像/容器等
rm -rf /var/lib/docker
网友评论