目录

测试-Docker-的实时恢复功能

测试 Docker 的实时恢复功能

1.编辑 Docker 守护进程配置文件/etc/docker/daemon. json,启用实时恢复功能。在该文件中添加以下内容


[root@host1 ~]# vi /etc/docker/daemon.json
[root@host1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://9fbd5949cbc94e4a9581e33b9077c811.mirror.swr.myhuaweicloud.com",
    "https://jnh8ca4k.mirror.aliyuncs.com"
  ],
  "insecure-registries": [
    "192.168.197.9:5000"
  ]
  "live-restore": true
}

2.重启 Docker 守护进程


[root@host1 ~]# vi /etc/docker/daemon.json
[root@host1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://9fbd5949cbc94e4a9581e33b9077c811.mirror.swr.myhuaweicloud.com",
    "https://jnh8ca4k.mirror.aliyuncs.com"
  ],
  "insecure-registries": [
    "192.168.197.9:5000"
  ]
  "live-restore": true
}
[root@host1 ~]# systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.
[root@host1 ~]# vi /etc/docker/daemon.json
[root@host1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://9fbd5949cbc94e4a9581e33b9077c811.mirror.swr.myhuaweicloud.com",
    "https://jnh8ca4k.mirror.aliyuncs.com"
  ],
  "insecure-registries": [
    "192.168.197.9:5000"
  ],
  "live-restore": true
}
[root@host1 ~]# systemctl restart docker
[root@host1 ~]# docker info
Client: Docker Engine - Community
 Version:    28.4.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.39.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 13
  Running: 1
  Paused: 0
  Stopped: 12
 Images: 20
 Server Version: 28.4.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
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.14.0-611.el9.x86_64
 Operating System: CentOS Stream 9
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.47GiB
 Name: host1
 ID: af1a50fb-c1e8-4693-96ea-aea71e06623b
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  192.168.197.9:5000
  ::1/128
  127.0.0.0/8
 Registry Mirrors:
  https://9fbd5949cbc94e4a9581e33b9077c811.mirror.swr.myhuaweicloud.com/
  https://jnh8ca4k.mirror.aliyuncs.com/
 Live Restore Enabled: true

        注意:第一次错误的原因是 json 格式的问题“少个英文逗号”,修改后成功运行!!!

3.基于 httpd 镜像创建一个运行 Apache 服务容器,然后查看正在运行的容器


[root@host1 ~]# docker run --rm -d --name web1 -p 8080:80 httpd
63625b693a81c137db99ab83ca90ef7ebf48bbf5b30a5923e7df99d9fd0d367b
[root@host1 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED          STATUS          PORTS                                         NAMES
63625b693a81   httpd      "httpd-foreground"        14 seconds ago   Up 13 seconds   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       web1
0dbf7ea2178e   registry   "/entrypoint.sh /etc…"   6 days ago       Up 3 minutes    0.0.0.0:5000->5000/tcp, [::]:5000->5000/tcp   myregistry

4.重新加载 Docker守护进程,然后查看正在运行的容器


[root@host1 ~]# systemctl reload docker
[root@host1 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED          STATUS          PORTS                                         NAMES
63625b693a81   httpd      "httpd-foreground"        50 seconds ago   Up 49 seconds   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       web1
0dbf7ea2178e   registry   "/entrypoint.sh /etc…"   6 days ago       Up 4 minutes    0.0.0.0:5000->5000/tcp, [::]:5000->5000/tcp   myregistry

5.使用 kill 命令结束 dockerd 守护进程,然后查看正在运行的容器


[root@host1 ~]# kill -SIGHUP $(pidof dockerd)
[root@host1 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                   CREATED         STATUS         PORTS                                         NAMES
63625b693a81   httpd      "httpd-foreground"        2 minutes ago   Up 2 minutes   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       web1
0dbf7ea2178e   registry   "/entrypoint.sh /etc…"   6 days ago      Up 5 minutes   0.0.0.0:5000->5000/tcp, [::]:5000->5000/tcp   myregistry

        可以发现该容器还在运行

6.访问该容器提供的 Apache 服务,结果表示该服务正常


[root@host1 ~]# curl http://127.0.0.1:8080
<html><body><h1>It works!</h1></body></html>

7.实验完毕,停止该容器后其自动被删除,恢复实验环境


[root@host1 ~]# docker stop logspout
Error response from daemon: No such container: logspout
[root@host1 ~]# docker ps -a
CONTAINER ID   IMAGE                          COMMAND                   CREATED          STATUS                        PORTS                                         NAMES
63625b693a81   httpd                          "httpd-foreground"        6 minutes ago    Up 6 minutes                  0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       web1
6a4be1b13463   alpine:latest                  "top"                     30 minutes ago   Exited (143) 30 minutes ago                                                 test
e9786682c0ba   redis                          "docker-entrypoint.s…"   49 minutes ago   Exited (0) 47 minutes ago                                                   redis
96632885a463   lagoudocker/cadvisor:v0.37.0   "/usr/bin/cadvisor -…"   24 hours ago     Exited (0) 24 hours ago                                                     cadvisor-stdout
62b9981bf08e   php-nginx-supervisor:v1        "/usr/bin/supervisor…"   37 hours ago     Exited (255) 33 hours ago     0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       php-web-app
7ecac05c7dac   centos-with-nginx:1.0          "nginx -g 'daemon of…"   6 days ago       Exited (255) 5 days ago       0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       test-nginx
0dbf7ea2178e   registry                       "/entrypoint.sh /etc…"   6 days ago       Up 9 minutes                  0.0.0.0:5000->5000/tcp, [::]:5000->5000/tcp   myregistry
c8efe28b118e   busybox                        "sh"                      6 days ago       Exited (137) 6 days ago                                                     stoic_raman
65a371a8cacb   httpd                          "httpd-foreground"        6 days ago       Exited (0) 6 days ago                                                       testweb
7ab5ac9bc007   ubuntu                         "/bin/bash"               6 days ago       Exited (0) 6 days ago                                                       inspiring_joliot
b97f426e8369   ubuntu                         "/bin/echo"               6 days ago       Exited (0) 6 days ago                                                       friendly_chaplygin
9ac8245b5b08   img-layers-test                "python /app/app.py"      8 days ago       Exited (0) 8 days ago                                                       crazy_kowalevski
49e91767b48d   ubuntu                         "/bin/bash"               8 days ago       Exited (0) 8 days ago                                                       frosty_lichterman
38b001022f7a   hello-world                    "/hello"                  8 days ago       Exited (0) 8 days ago                                                       intelligent_brahmagupta
[root@host1 ~]# docker stop web1
web1