Reboot or Shutdown in a Container

Function Description

The reboot and shutdown commands can be executed in a system container. You can run the reboot command to restart a container, and run the shutdown command to stop a container.

Parameter Description

Command

Parameter

Value Description

isula create/run

--restart

  • Variable of the string type.
  • Supported option is as follows:

    on-reboot: restarts the system container.

      

Constraints

  • The shutdown function relies on the actual OS of the container running environment.
  • When you run the shutdown -h now command to shut down the system, do not open multiple consoles. For example, if you run the isula run -ti command to open a console and run the isula attach command for the container in another host bash, another console is opened. In this case, the shutdown command fails to be executed.

Example

  • Specify the –restart on-reboot parameter when starting a container. For example:

    [root@localhost ~]# isula run -tid --restart on-reboot --system-container --external-rootfs /root/myrootfs none init
    106faae22a926e22c828a0f2b63cf5c46e5d5986ea8a5b26de81390d0ed9714f
    
  • In the container, run the reboot command.

    [root@localhost ~]# isula exec -it 10 bash
    [root@localhost /]# reboot
    

    Check whether the container is restarted.

    [root@localhost ~]# isula exec -it 10 ps aux
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.1  0.0  21588  9504 ?        Ss   12:11   0:00 init
    root        14  0.1  0.0  27024  9376 ?        Ss   12:11   0:00 /usr/lib/system
    root        17  0.0  0.0  18700  5876 ?        Ss   12:11   0:00 /usr/lib/system
    dbus        22  0.0  0.0   9048  3624 ?        Ss   12:11   0:00 /usr/bin/dbus-d
    root        26  0.0  0.0   8092  3012 ?        Rs+  12:13   0:00 ps aux
    
  • In the container, run the shutdown command.

    [root@localhost ~]# isula exec -it 10 bash
    [root@localhost /]# shutdown -h now
    [root@localhost /]# [root@localhost ~]#
    

    Check whether the container is stopped.

    [root@localhost ~]# isula exec -it 10 bash
    Error response from daemon: Exec container error;Container is not running:106faae22a926e22c828a0f2b63cf5c46e5d5986ea8a5b26de81390d0ed9714f
    
Rating

search results about are found