IT评测·应用市场-qidao123.com技术社区

标题: Rocky Linux9下安装Docker和卸载Docker [打印本页]

作者: 种地    时间: 2024-12-28 16:23
标题: Rocky Linux9下安装Docker和卸载Docker
前提条件

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

安装Docker

精简版下令

  1. yum install -y yum-utils
  2. yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3. yum install -y docker-ce
  4. systemctl enable docker --now
  5. mkdir -p /etc/docker
  6. tee /etc/docker/daemon.json <<-'EOF'
  7. {
  8.   "registry-mirrors": [
  9.     "https://registry.docker-cn.com",
  10.     "http://hub-mirror.c.163.com",
  11.     "https://docker.mirrors.ustc.edu.cn"
  12.   ]
  13. }
  14. EOF
  15. systemctl daemon-reload
  16. systemctl restart docker
  17. docker version
  18. docker info
  19. docker run hello-world
复制代码

具体操作过程

安装须要的包
  1. [root@localhost ~]# yum install -y yum-utils
  2. Last metadata expiration check: 0:25:51 ago on Mon Sep  9 15:49:04 2024.
  3. Package yum-utils-4.3.0-13.el9.noarch is already installed.
  4. Dependencies resolved.
  5. Nothing to do.
  6. Complete!
复制代码

添加docker-ce repo
  1. [root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
复制代码

安装docker-ce
  1. [root@localhost ~]# yum install -y docker-ce
  2. ...
  3. 省略日志输出
  4. ...
复制代码
设置开机主动启动docker及启动docker
  1. [root@localhost ~]# systemctl enable docker --now
复制代码
配置国内镜像加速,这里配置三个镜像加速地址,根据需要可以添加更多镜像地址
  1. [root@localhost ~]# mkdir -p /etc/docker
  2. [root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
  3. {
  4.   "registry-mirrors": [
  5.    "https://registry.docker-cn.com",
  6.    "http://hub-mirror.c.163.com",
  7.    "https://docker.mirrors.ustc.edu.cn"
  8.   ]
  9. }
  10. EOF
  11. {
  12.   "registry-mirrors": [
  13.    "https://registry.docker-cn.com",
  14.    "http://hub-mirror.c.163.com",
  15.    "https://docker.mirrors.ustc.edu.cn"
  16.   ]
  17. }
复制代码

重新加载配置及重启docker
  1. [root@localhost ~]# systemctl daemon-reload
  2. [root@localhost ~]# systemctl restart docker
复制代码

查看docker版本信息
  1. [root@localhost ~]# docker version
  2. Client: Docker Engine - Community
  3. Version:           27.2.0
  4. API version:       1.47
  5. Go version:        go1.21.13
  6. Git commit:        3ab4256
  7. Built:             Tue Aug 27 14:17:06 2024
  8. OS/Arch:           linux/amd64
  9. Context:           default
  10. Server: Docker Engine - Community
  11. Engine:
  12.   Version:          27.2.0
  13.   API version:      1.47 (minimum version 1.24)
  14.   Go version:       go1.21.13
  15.   Git commit:       3ab5c7d
  16.   Built:            Tue Aug 27 14:15:14 2024
  17.   OS/Arch:          linux/amd64
  18.   Experimental:     false
  19. containerd:
  20.   Version:          1.7.21
  21.   GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
  22. runc:
  23.   Version:          1.1.13
  24.   GitCommit:        v1.1.13-0-g58aa920
  25. docker-init:
  26.   Version:          0.19.0
  27.   GitCommit:        de40ad0
复制代码

查看docker信息
  1. [root@localhost ~]# docker info
  2. Client: Docker Engine - Community
  3. Version:    27.2.0
  4. Context:    default
  5. Debug Mode: false
  6. Plugins:
  7.   buildx: Docker Buildx (Docker Inc.)
  8.    Version:  v0.16.2
  9.    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  10.   compose: Docker Compose (Docker Inc.)
  11.    Version:  v2.29.2
  12.    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  13. Server:
  14. Containers: 0
  15.   Running: 0
  16.   Paused: 0
  17.   Stopped: 0
  18. Images: 0
  19. Server Version: 27.2.0
  20. Storage Driver: overlay2
  21.   Backing Filesystem: xfs
  22.   Supports d_type: true
  23.   Using metacopy: false
  24.   Native Overlay Diff: true
  25.   userxattr: false
  26. Logging Driver: json-file
  27. Cgroup Driver: systemd
  28. Cgroup Version: 2
  29. Plugins:
  30.   Volume: local
  31.   Network: bridge host ipvlan macvlan null overlay
  32.   Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
  33. Swarm: inactive
  34. Runtimes: runc io.containerd.runc.v2
  35. Default Runtime: runc
  36. Init Binary: docker-init
  37. containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
  38. runc version: v1.1.13-0-g58aa920
  39. init version: de40ad0
  40. Security Options:
  41.   seccomp
  42.   Profile: builtin
  43.   cgroupns
  44. Kernel Version: 5.14.0-427.33.1.el9_4.x86_64
  45. Operating System: Rocky Linux 9.4 (Blue Onyx)
  46. OSType: linux
  47. Architecture: x86_64
  48. CPUs: 4
  49. Total Memory: 3.543GiB
  50. Name: localhost.localdomain
  51. ID: 24d90a1d-c5bf-41c9-862e-cab401d7b832
  52. Docker Root Dir: /var/lib/docker
  53. Debug Mode: false
  54. Experimental: false
  55. Insecure Registries:
  56.   127.0.0.0/8
  57. Registry Mirrors:
  58.   https://registry.docker-cn.com/
  59.   http://hub-mirror.c.163.com/
  60.   https://docker.mirrors.ustc.edu.cn/
  61. Live Restore Enabled: false
  62. [root@localhost ~]#
复制代码

验证docker是否可用
下载一个 “hello-world” 测试镜像并在容器中运行它,当容器运行时,它会打印确认消息并退出。
  1. [root@localhost ~]# docker run hello-world
  2. Unable to find image 'hello-world:latest' locally
  3. latest: Pulling from library/hello-world
  4. c1ec31eb5944: Pull complete
  5. Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
  6. Status: Downloaded newer image for hello-world:latest
  7. Hello from Docker!
  8. This message shows that your installation appears to be working correctly.
  9. To generate this message, Docker took the following steps:
  10. 1. The Docker client contacted the Docker daemon.
  11. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  12.    (amd64)
  13. 3. The Docker daemon created a new container from that image which runs the
  14.    executable that produces the output you are currently reading.
  15. 4. The Docker daemon streamed that output to the Docker client, which sent it
  16.    to your terminal.
  17. To try something more ambitious, you can run an Ubuntu container with:
  18. $ docker run -it ubuntu bash
  19. Share images, automate workflows, and more with a free Docker ID:
  20. https://hub.docker.com/
  21. For more examples and ideas, visit:
  22. https://docs.docker.com/get-started/
  23. [root@localhost ~]#
复制代码
提示:网络的原因可能需要多实验几次才气下载乐成,如果下载不了,还可以实验添加更多可用镜像。

卸载docker

卸载docker下令
  1. [root@localhost ~]# yum remove -y docker-ce
复制代码

删除docker相干文件
主机上的镜像、容器、卷或自定义配置文件不会主动删除,使用如下下令删除所有的镜像、容器和卷。
  1. [root@localhost ~]# rm -rf /var/lib/docker
  2. [root@localhost ~]# rm -rf /var/lib/containerd
复制代码

完成!enjoy it!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4