当前位置: 首页 > news >正文

Rocky Linux9下安装Docker和卸载Docker

前提条件

安装好Rocky Linux9,可参考 Vmware下安装Rocky Linux9.4

安装Docker

精简版命令

yum install -y yum-utilsyum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoyum install -y docker-cemkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
}
EOFsystemctl daemon-reloadsystemctl restart dockerdocker versiondocker infodocker run hello-world

详细操作过程

安装必要的包

[root@localhost ~]# yum install -y yum-utils
Last metadata expiration check: 0:25:51 ago on Mon Sep  9 15:49:04 2024.
Package yum-utils-4.3.0-13.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

添加docker-ce repo

[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装docker-ce

[root@localhost ~]# yum install -y docker-ce
...
省略日志输出
...

配置国内镜像加速,这里配置三个镜像加速地址,根据需要可以添加更多镜像地址

[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
}
EOF
{"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
}

重新加载配置及重启docker

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

查看docker版本信息

[root@localhost ~]# docker version
Client: Docker Engine - CommunityVersion:           27.2.0API version:       1.47Go version:        go1.21.13Git commit:        3ab4256Built:             Tue Aug 27 14:17:06 2024OS/Arch:           linux/amd64Context:           default
​
Server: Docker Engine - CommunityEngine:Version:          27.2.0API version:      1.47 (minimum version 1.24)Go version:       go1.21.13Git commit:       3ab5c7dBuilt:            Tue Aug 27 14:15:14 2024OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.7.21GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111runc:Version:          1.1.13GitCommit:        v1.1.13-0-g58aa920docker-init:Version:          0.19.0GitCommit:        de40ad0

查看docker信息

[root@localhost ~]# docker info
Client: Docker Engine - CommunityVersion:    27.2.0Context:    defaultDebug Mode: falsePlugins:buildx: Docker Buildx (Docker Inc.)Version:  v0.16.2Path:     /usr/libexec/docker/cli-plugins/docker-buildxcompose: Docker Compose (Docker Inc.)Version:  v2.29.2Path:     /usr/libexec/docker/cli-plugins/docker-compose
​
Server:Containers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 27.2.0Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueUsing metacopy: falseNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: systemdCgroup Version: 2Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local splunk syslogSwarm: inactiveRuntimes: runc io.containerd.runc.v2Default Runtime: runcInit Binary: docker-initcontainerd version: 472731909fa34bd7bc9c087e4c27943f9835f111runc version: v1.1.13-0-g58aa920init version: de40ad0Security Options:seccompProfile: builtincgroupnsKernel Version: 5.14.0-427.33.1.el9_4.x86_64Operating System: Rocky Linux 9.4 (Blue Onyx)OSType: linuxArchitecture: x86_64CPUs: 4Total Memory: 3.543GiBName: localhost.localdomainID: 24d90a1d-c5bf-41c9-862e-cab401d7b832Docker Root Dir: /var/lib/dockerDebug Mode: falseExperimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors:https://registry.docker-cn.com/http://hub-mirror.c.163.com/https://docker.mirrors.ustc.edu.cn/Live Restore Enabled: false
​
[root@localhost ~]# 
​

验证docker是否可用

下载一个 “hello-world” 测试镜像并在容器中运行它,当容器运行时,它会打印确认消息并退出。

[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto 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 ID:https://hub.docker.com/
​
For more examples and ideas, visit:https://docs.docker.com/get-started/
​
[root@localhost ~]# 
​

提示:网络的原因可能需要多尝试几次才能下载成功,如果下载不了,还可以尝试添加更多可用镜像。

卸载docker

卸载docker命令

[root@localhost ~]# yum remove -y docker-ce

删除docker相关文件

主机上的镜像、容器、卷或自定义配置文件不会自动删除,使用如下命令删除所有的镜像、容器和卷。

[root@localhost ~]# rm -rf /var/lib/docker
[root@localhost ~]# rm -rf /var/lib/containerd

完成!enjoy it!


http://www.mrgr.cn/news/23208.html

相关文章:

  • CTK框架(六):服务工厂
  • 重卡换电解决方案换电连接器
  • Flink
  • 代码随想录打卡Day27
  • AI绘图神器排行:MidJourney、Stable Diffusion等热门工具深度解析
  • 【SPIE独立出版,连续2届稳定EI检索!】2024年第三届信息学,网络与计算技术国际学术会议(ICINC2024,10月25-27)
  • Python 数学建模——假设检验
  • 设计模式应用
  • 【学习笔记】手写 Tomcat -- 预备知识
  • Linux:多路转接 select、poll、epoll
  • Mysql Innodb存储引擎原理—链接如下
  • [Python]使用python统计docx文档字符、单词数
  • 反序列化漏洞练习1
  • 20章 线性表、栈、队列和优先队列
  • 前端面试热点题目——typescript篇
  • 苍穹外卖()
  • 【数据结构与算法 | 灵神题单 | 删除链表篇】力扣2487, 237
  • LeetCode之字典树
  • 输入子系统
  • Qt常用控件——QRadioButton和QCheckBox