0

I'm working with a Docker container with Debian 11 inside and a server. I need to update this server and do other things on regular manne. I've written several scripts that can do it, but I encountered serious proble. If I want to update the server and other packages I need to reboot the container. I'm obviously able to do so from the computer Docker is installed on (in my case Docker Desktop running with WSL2 on Windows 10), I can reboot the container easily, but I need to automate it. The simplest way will be to add the shutdown command to the scripts I've written. I was reading about it, but found nothing. Is there any way to reboot this container from the Debian inside it? If no, how can it be achieved and how complicated is it?

I was trying to invoke standard Linux commands to shutdown or reboot system on Debian inside container. I expect a guide if it's possible and worth efforts.

Aenye_Cerbin
  • 158
  • 10
  • 2
    _Reboot_ a container? A container doesn't have its own kernel. Yes, it has a Debian 11 userland, but your container does not have a Debian 11 kernel, and so you can't reboot that. Also, you wouldn't update the container. Instead, you update the _image_, and create a new container. – MSalters Dec 02 '22 at 08:31
  • 1
    Docker containers shouldn't be responsible for orchestrating themselves. If you need to reboot the host, just shut it down. Docker will restart the containers when it comes back up. More here: https://docs.docker.com/config/containers/start-containers-automatically/ – Hans Kilian Dec 02 '22 at 09:06

1 Answers1

2

The only way to trigger a restart of a container from within the container is to first set a restart policy on the container such as --restart=on-failure and then simply stop the container, i.e., let the main process terminate itself. The Docker engine would then restart the container.

This, however, is not the way Docker is intended to be used! Docker containers are not VMs and instead are meant to be ephemeral:

By "ephemeral", we mean that the container can be stopped and destroyed, then rebuilt and replaced with an absolute minimum set up and configuration.

This means, you shouldn't be updating the server within a running container but instead should update/rebuild the image and start a new container from it!

acran
  • 7,070
  • 1
  • 18
  • 35