--- title: docker的安装卸载 description: docker的安装与卸载 published: true date: 2021-12-09T06:35:41.502Z tags: docker editor: markdown dateCreated: 2021-08-02T07:22:52.894Z --- # 安装Docker ## CentOS #### 自动安装 ```bash $ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun ``` #### 手动安装 ##### 卸载旧版本 ```bash $ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine ``` 或者查看已经安装的docker ```bash $ yum list installed |grep docker ``` ##### 安装 [官方安装传送门](https://docs.docker.com/engine/install/centos/) ###### 下载依赖 [选择对应CentOS版本](https://download.docker.com/linux/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 ###### 执行安装 ```bash $ 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+) ```bash $ cat /etc/redhat-release # CentOS Linux release 7.3.1611 (Core) ``` [安装包传送门](https://download.docker.com/linux/static/stable/x86_64/) 这里下载的版本是:docker-19.03.9.tgz 1. 解压与安装 ```bash $ cd /usr/local/resource/docker $ tar -xzvf docker-18.06.3-ce.tar # 将二进制文件移动到bin下 $ mv /usr/local/resource/docker/docker/* /usr/bin/ ``` 2. 编写 docker.service ```bash $ vim /etc/systemd/system/docker.service ``` 3. 将以下内容粘贴进去: ```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 -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 ``` 4. 授予执行权限 ```bash $ chmod +x /etc/systemd/system/docker.service ``` 5. 重载service ```bash $ systemctl daemon-reload ``` #### 启动docker 设置开机启动 ```bash $ systemctl enable docker ``` 启动 ```bash $ systemctl start docker ``` #### 删除 ##### 删除安装包 ```bash $ yum remove docker-ce ``` ##### 删除镜像、容器、配置文件等 ```bash $ rm -rf /var/lib/docker ```