wiki-files/docker/install.md

164 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

2021-08-02 15:22:54 +08:00
---
2021-09-02 14:22:26 +08:00
title: docker的安装卸载
description: docker的安装与卸载
2021-08-02 15:22:54 +08:00
published: true
2021-12-09 14:35:42 +08:00
date: 2021-12-09T06:35:41.502Z
2021-08-02 15:27:14 +08:00
tags: docker
2021-08-02 15:22:54 +08:00
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
```
2021-09-02 14:20:06 +08:00
或者查看已经安装的docker
```bash
$ yum list installed |grep docker
```
2021-08-02 15:22:54 +08:00
##### 安装
2021-09-02 14:20:06 +08:00
[官方安装传送门](https://docs.docker.com/engine/install/centos/)
###### 下载依赖
2021-08-02 15:22:54 +08:00
2021-09-02 14:20:06 +08:00
[选择对应CentOS版本](https://download.docker.com/linux/centos/)
2021-08-02 15:22:54 +08:00
2021-09-02 14:20:06 +08:00
下载stable版本的两个文件这里是CentOS7.5
2021-09-09 09:36:55 +08:00
最新安装
- 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
2021-12-09 14:34:54 +08:00
- docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
2021-09-09 09:36:55 +08:00
- docker-ce-cli-18.09.4-3.el7.x86_64.rpm
2021-12-09 14:34:54 +08:00
- docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
2021-08-02 15:22:54 +08:00
2021-09-02 14:20:06 +08:00
###### 执行安装
```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
```
2021-12-09 14:34:54 +08:00
#### 离线安装
环境contos7.3(内核需为3.10+)
```bash
2021-12-09 14:35:42 +08:00
$ cat /etc/redhat-release
2021-12-09 14:34:54 +08:00
# CentOS Linux release 7.3.1611 (Core)
```
[安装包传送门](https://download.docker.com/linux/static/stable/x86_64/)
这里下载的版本是docker-19.03.9.tgz
1. 解压与安装
```bash
2021-12-09 14:35:42 +08:00
$ cd /usr/local/resource/docker
$ tar -xzvf docker-18.06.3-ce.tar
2021-12-09 14:34:54 +08:00
# 将二进制文件移动到bin下
2021-12-09 14:35:42 +08:00
$ mv /usr/local/resource/docker/docker/* /usr/bin/
2021-12-09 14:34:54 +08:00
```
2. 编写 docker.service
```bash
2021-12-09 14:35:42 +08:00
$ vim /etc/systemd/system/docker.service
2021-12-09 14:34:54 +08:00
```
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
2021-12-09 14:35:42 +08:00
$ chmod +x /etc/systemd/system/docker.service
2021-12-09 14:34:54 +08:00
```
5. 重载service
```bash
2021-12-09 14:35:42 +08:00
$ systemctl daemon-reload
2021-12-09 14:34:54 +08:00
```
2021-09-02 14:20:06 +08:00
#### 启动docker
设置开机启动
2021-08-02 15:22:54 +08:00
```bash
2021-09-02 14:20:06 +08:00
$ systemctl enable docker
2021-08-02 15:22:54 +08:00
```
2021-09-02 14:20:06 +08:00
启动
2021-08-02 15:22:54 +08:00
```bash
2021-09-02 14:20:06 +08:00
$ systemctl start docker
2021-08-02 15:22:54 +08:00
```
#### 删除
##### 删除安装包
```bash
$ yum remove docker-ce
```
##### 删除镜像、容器、配置文件等
```bash
$ rm -rf /var/lib/docker
```