当前位置:首页 » 《休闲阅读》 » 正文

Rocky Linux9下安装Docker和卸载Docker

13 人参与  2024年10月22日 14:02  分类 : 《休闲阅读》  评论

点击全文阅读


前提条件

安装好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-cesystemctl enable docker --nowmkdir -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-utilsLast 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.repoAdding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装docker-ce

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

设置开机自动启动docker及启动docker

[root@localhost ~]# systemctl enable docker --now

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

[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 versionClient: Docker Engine - Community Version:           27.2.0 API version:       1.47 Go version:        go1.21.13 Git commit:        3ab4256 Built:             Tue Aug 27 14:17:06 2024 OS/Arch:           linux/amd64 Context:           default​Server: Docker Engine - Community Engine:  Version:          27.2.0  API version:      1.47 (minimum version 1.24)  Go version:       go1.21.13  Git commit:       3ab5c7d  Built:            Tue Aug 27 14:15:14 2024  OS/Arch:          linux/amd64  Experimental:     false containerd:  Version:          1.7.21  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111 runc:  Version:          1.1.13  GitCommit:        v1.1.13-0-g58aa920 docker-init:  Version:          0.19.0  GitCommit:        de40ad0

查看docker信息

[root@localhost ~]# docker infoClient: Docker Engine - Community Version:    27.2.0 Context:    default Debug Mode: false Plugins:  buildx: Docker Buildx (Docker Inc.)    Version:  v0.16.2    Path:     /usr/libexec/docker/cli-plugins/docker-buildx  compose: Docker Compose (Docker Inc.)    Version:  v2.29.2    Path:     /usr/libexec/docker/cli-plugins/docker-compose​Server: Containers: 0  Running: 0  Paused: 0  Stopped: 0 Images: 0 Server Version: 27.2.0 Storage Driver: overlay2  Backing Filesystem: xfs  Supports d_type: true  Using metacopy: false  Native Overlay Diff: true  userxattr: false Logging Driver: json-file Cgroup Driver: systemd Cgroup Version: 2 Plugins:  Volume: local  Network: bridge host ipvlan macvlan null overlay  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: runc io.containerd.runc.v2 Default Runtime: runc Init Binary: docker-init containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111 runc version: v1.1.13-0-g58aa920 init version: de40ad0 Security Options:  seccomp   Profile: builtin  cgroupns Kernel Version: 5.14.0-427.33.1.el9_4.x86_64 Operating System: Rocky Linux 9.4 (Blue Onyx) OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 3.543GiB Name: localhost.localdomain ID: 24d90a1d-c5bf-41c9-862e-cab401d7b832 Docker Root Dir: /var/lib/docker Debug Mode: false Experimental: false Insecure Registries:  127.0.0.0/8 Registry 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-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldc1ec31eb5944: Pull complete Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75Status: 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 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://zhangshiyu.com/post/175490.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1