wiki-files/docker/install.md

3.5 KiB
Raw Permalink Blame History

title description published date tags editor dateCreated
docker的安装卸载 docker的安装与卸载 true 2021-12-09T06:35:41.502Z docker markdown 2021-08-02T07:22:52.894Z

安装Docker

CentOS

自动安装

$ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

手动安装

卸载旧版本
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

或者查看已经安装的docker

$ yum list installed |grep docker
安装

官方安装传送门

下载依赖

选择对应CentOS版本

下载stable版本的两个文件这里是CentOS7.5

最新安装

  • containerd.io-1.4.9-3.1.el7.x86_64.rpm
  • docker-ce-20.10.8-3.el7.x86_64.rpm

旧版本安装

  • containerd.io-1.2.5-3.1.el7.x86_64.rpm
  • docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
  • docker-ce-cli-18.09.4-3.el7.x86_64.rpm
  • docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
执行安装
$ yum install -y docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
$ yum install -y docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm

离线安装

环境contos7.3(内核需为3.10+)

$ cat /etc/redhat-release
# CentOS Linux release 7.3.1611 (Core)

安装包传送门

这里下载的版本是docker-19.03.9.tgz

  1. 解压与安装
$ cd /usr/local/resource/docker
$ tar -xzvf docker-18.06.3-ce.tar
# 将二进制文件移动到bin下
$ mv  /usr/local/resource/docker/docker/*  /usr/bin/
  1. 编写 docker.service
$ vim /etc/systemd/system/docker.service
  1. 将以下内容粘贴进去:
[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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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
  1. 授予执行权限
$ chmod +x /etc/systemd/system/docker.service
  1. 重载service
$ systemctl daemon-reload

启动docker

设置开机启动

$ systemctl enable docker

启动

$ systemctl start docker

删除

删除安装包
$ yum remove docker-ce
删除镜像、容器、配置文件等
$ rm -rf /var/lib/docker