CentOS系统下docker的安装与卸载

简介: CentOS系统下,docker安装及卸载方法,包括常规方式安装及脚本一键安装。

一、docker安装与启动

1.安装docker的几种方式

1)安装最新版本docker

① 先卸载旧版本的docker

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

② 指定Docker下载源(可选,适用于首次安装)

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装Docker(默认安装最新版本)

yum install docker-ce docker-ce-cli containerd.io

验证是否安装成功

docker version

2)安装指定版本的docker

yum list docker-ce --showduplicates | sort-r# 查看所有可用版本yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io  # 安装指定版本

3)通过脚本一键安装docker

脚本内容如下:

#!/bin/bashecho"set default docker install repo"yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
echo"install docker ..."yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl status docker

2.启动docker

systemctl start docker  # 启动服务systemctl status docker  # 查看状态systemctl stop docker  # 停止服务systemctl restart docker  # 重启服务

二、创建第一个docker容器

1.创建容器

按照国际惯例,先运行一个hello-world的容器

docker run hello-world
# 如果网络等一切正常的话,会出现如下提示,表示容器已经创建成功Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:18a657d0cc1c7d0678a3fbea8b7eb4918bba25968d3e1b0adebfa71caddbc346
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.
    (amd64)
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 bashShare images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2.查看容器

docker ps-a# 查看所有容器# 创建成功,容器列表中就会有hello-world的容器,但名字不是hello-world,因为我们在运行容器时并未指定名称CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
a07f1a8ea1a4   hello-world   "/hello"21 seconds ago   Exited (0) 20 seconds ago             adoring_chatterjee

三、卸载docker

1.常规方式卸载

① 停止docker服务

systemctl stop docker

② 搜索已经安装的docker安装包

yum list installed | grep docker
rpm -qa | grep docker
yum -y remove docker-ce.x86_64 
yum -y remove docker-ce-cli.x86_64 
yum -y remove containerd.io.x86_64

③ 移除所有相关安装包

yum -y remove contained.io.x86_64

④ 删除docker镜像及相关文件夹

rm-rf /var/lib/docker

2.脚本卸载

所谓的使用脚本安装和卸载,通俗理解就是把上述多个操作步骤的命令放在一个脚本中批量执行,内容如下:

#!/bin/bashsystemctl stop docker
yum -y remove docker-ce.x86_64
yum -y remove docker-ce-cli.x86_64
yum -y remove containerd.io.x86_64
rm-rf /var/lib/docker
rm-rf /etc/docker/daemon.json
相关文章
|
2天前
|
弹性计算 安全 Cloud Native
Alibaba Cloud Linux镜像系统超好用!兼容CentOS生态,性能稳定性绝对可以!
Alibaba Cloud Linux是阿里云的自研Linux发行版,兼容CentOS/RHEL,提供长期免费支持。它针对云服务器ECS优化,适用于多种场景,如Web服务、云原生应用等。Alibaba Cloud Linux 3基于Anolis OS 8,提供安全、高性能、十年维护及丰富的开源生态。用户可在ECS购买时选择镜像安装,支持多架构并提供热补丁、解决方案和快速启动版。更换ECS操作系统是免费的。
32 5
|
1天前
|
Linux Docker 容器
Centos8安装Docker
Centos8安装Docker
13 1
|
2天前
|
Ubuntu Docker 容器
ubuntu安装docker
ubuntu安装docker
33 1
|
20小时前
|
应用服务中间件 nginx Docker
Docker安装与管理Nginx
Docker安装与管理Nginx
13 0
|
20小时前
|
缓存 Linux Docker
CentOS 7 下安装 Docker 及配置阿里云加速服务
CentOS 7 下安装 Docker 及配置阿里云加速服务
9 0
|
1天前
|
Docker 容器
技术经验分享:Docker安装及更换源
技术经验分享:Docker安装及更换源
12 0
|
1天前
|
关系型数据库 MySQL 数据库
轻松入门:使用Docker安装MySQL数据库的完全指南
轻松入门:使用Docker安装MySQL数据库的完全指南
|
1天前
|
NoSQL Linux 数据安全/隐私保护
轻松搭建Neo4j图数据库:一步步教你在Docker上安装Neo4j Community Server
轻松搭建Neo4j图数据库:一步步教你在Docker上安装Neo4j Community Server
|
2天前
|
Linux 虚拟化 Docker
Docker在windows安装(Win11,docker20.10.23)
Docker在windows安装(Win11,docker20.10.23)
19 0
|
2天前
|
NoSQL 关系型数据库 MySQL
一文学会dockers安装 (附docker安装MySQL、Redis)
一文学会dockers安装 (附docker安装MySQL、Redis)
23 0