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
相关文章
|
1月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
390 69
|
1月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
201 78
|
2月前
|
缓存 NoSQL Linux
在CentOS 7系统中彻底移除MongoDB数据库的步骤
以上步骤完成后,MongoDB应该会从您的CentOS 7系统中被彻底移除。在执行上述操作前,请确保已经备份好所有重要数据以防丢失。这些步骤操作需要一些基本的Linux系统管理知识,若您对某一步骤不是非常清楚,请先进行必要的学习或咨询专业人士。在执行系统级操作时,推荐在实施前创建系统快照或备份,以便在出现问题时能够恢复到原先的状态。
231 79
|
20天前
|
缓存 监控 Linux
CentOS系统如何查看当前内存容量。
以上方法都不需要特殊软件或者复杂配置即可执行,在CentOS或其他Linux发行版中都适合运行,并且它们各自透露出不同角度对待问题解答方式:从简单快速到深入详尽;从用户态到核心态;从操作层数到硬件层数;满足不同用户需求与偏好。
146 8
|
27天前
|
存储 Linux 数据安全/隐私保护
确定CentOS系统分区表类型(MBR或GPT)
以上方法均能够帮助用户准确地识别出CentOS下连接硬件所应用得具体磁盘标准,并根据实际需求做进一步处理与管理工作。
148 0
|
3月前
|
机器人 Linux
CentOS 7系统中安装特定版本CMake 3.21.2的方法。
到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
201 18
|
1月前
|
Ubuntu Linux 云计算
CentOS与Ubuntu:Linux系统的双璧
选择Ubuntu还是CentOS,取决于用户的具体需求,如是否需要图形化界面、对稳定性的要求、软件包管理的偏好以及对商业支持的需求等。两者都是优秀的Linux发行版,只是在设计理念和目标用户群体上有所不同。#深度好文计划#
|
Ubuntu 网络安全 数据安全/隐私保护
百度搜索:蓝易云【docker通过dockerfile安装sftp教程。】
现在,你已经通过 Dockerfile 成功安装了 SFTP,并且可以使用指定的用户名和公钥进行远程访问。请确保替换示例中的用户名、密码和公钥为自己的实际值。
272 1
|
10月前
|
缓存 Linux Docker
【最新版正确姿势】Docker安装教程(简单几步即可完成)
之前的老版本Docker安装教程已经发生了变化,本文分享了Docker最新版安装教程,其他操作系统版本也可以参考官 方的其他安装版本文档。
9868 4
【最新版正确姿势】Docker安装教程(简单几步即可完成)