Docker安装和卸载

简介: 一:卸载旧版本 老版本的Docker被称为docker或docker-engine。如果安装了这些,请卸载它们以及相关的依赖项。 $ sudo yum remove docker \ docker-common \ docker-selinux \ docker-engine 如果yum报告说没有安装这些软件包,那么也行。

一:卸载旧版本

老版本的Docker被称为dockerdocker-engine如果安装了这些,请卸载它们以及相关的依赖项。

$ sudo yum remove docker \
                  docker-common \
                  docker-selinux \
                  docker-engine

如果yum报告说没有安装这些软件包,那么也行。

 二:安装Docker CE

1. 更新系统

#yum update -y

 

2. 添加 docker 版本仓库

cat >/etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
EOF

 

3. 安装 docker

docker 在 17 年 3 月份后,Docker 分成了企业版(EE)和社区版(CE),转向基于时间的 YY.MM 形式的版本控制方案,17.03 相当于 1.13.1 版本

#yum install docker-ce

 

安装旧版本 (1.12) 方法 yum install docker-engine

4. 设置 docker 开机自启动

#systemctl enable docker.service

 

5. 启动 Docker daemon

#systemctl start docker

 

6. 验证 docker 安装是否成功

#docker run --rm hello-world
--------------------------------------------------- 以下是程序输出
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
   1. The Docker client contacted the Docker daemon.
   2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
   3. The Docker daemon created a new container from that image which runs the
      executable that produces the output you are currently reading.
   4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

7. 创建 docker 组

将 host 下的普通用户添加到 docker 组中后,可以不使用 sudo 即可执行 docker 程序(只是减少了每次使用 sudo 时输入密码的过程罢了,其实 docker 本身还是以 sudo 的权限在运行的。)

sudo usermod -aG docker your_username

 

8. 其他配置

设置 ipv4 转发(centos 上需要配置),实践中发现 Ubuntu 和 Suse 上无需配置

查看

#sysctl net.ipv4.ip_forward

 

临时更改

#sysctl -w net.ipv4.ip_forward=1

 

永久更改

#echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
#sysctl -p
#sysctl net.ipv4.ip_forward

 

三: 卸载 docker

方法1:

1. 列出安装的 docker

yum list installed | grep docker

 

2. 删除安装包

sudo yum -y remove docker-engine.x86_64

 

3. 删除数据文件

rm -rf /var/lib/docker

 方法2

rpm方法卸载

rpm -e --nodeps `rpm -aq |grep docker`

  





目录
相关文章
|
4天前
|
Linux 虚拟化 Docker
Windows12安装Docker
Windows12安装Docker
26 2
|
26天前
|
Docker 容器
卸载Docker
当Docker卸载残留组件时,需手动清理。执行`yum remove`移除多个Docker相关包,包括client、common和selinux版本。接着删除`/etc/systemd/system/docker.service.d`、`/var/lib/docker`和`/var/run/docker`目录。先用`yum list installed | grep docker`列出已安装包,再用`yum -y remove`卸载`docker-ce`和`docker-ce-selinux`。
23 0
|
1天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
3 0
|
2天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(7)Ubuntu20.04 arm64安装Docker
Linux(7)Ubuntu20.04 arm64安装Docker
10 0
|
2天前
|
存储 Ubuntu Docker
如何在 Ubuntu 上安装 Docker?
【4月更文挑战第17天】
32 8
如何在 Ubuntu 上安装 Docker?
|
4天前
|
Kubernetes 数据安全/隐私保护 数据中心
Portainer的安装(docker)
Portainer的安装(docker)
13 0
|
5天前
|
Ubuntu Docker 索引
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
28 0
|
12天前
|
时序数据库 Docker 容器
Docker安装InfluxDB
Docker安装InfluxDB
11 0
|
12天前
|
关系型数据库 MySQL 数据库
Docker安装MySQL
Docker安装MySQL
24 1
|
14天前
|
关系型数据库 MySQL 数据库
docker自定义安装mysql 5.7
docker自定义安装mysql 5.7
22 0