Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you install something that needs restart in a Dockerfile?

Suppose I have installation instructions as follows:

  1. Do something.
  2. Reboot your machine.
  3. Do something else.

How do I express that in a Dockerfile?

like image 496
Fernando Tiberti Avatar asked Sep 26 '16 21:09

Fernando Tiberti


1 Answers

This entirely depends on why they require a reboot. For Linux, rebooting a machine would typically indicate a kernel modification, though it's possible it's for something more simple like a change in user permissions (which would be handled by logging out and back in again). If the install is trying to make an OS level change to the kernel, it should fail if done inside of a container. By default, containers isolate and restrict what the application can do to the running host OS which would impact the host or other running containers.

If, the reboot is to force the application service to restart, you should realize that this design doesn't map well to a container since each RUN command runs just that command in an isolated environment. And by running only that command, this also indicates that any OS services that would normally be started on OS bootup (cron, sendmail, or your application) will not be started in the container. Therefore, you'll need to find a way to run the installation command in addition to restarting any dependent services.

The last scenario I can think of they want different user permissions to take effect to the logged in user. In that case, the next RUN command will run the requested command with any changed access from prior RUN commands. So there's no need to take any specific action of your own to do a reboot, simply perform the install steps as if there's a complete restart between each step.

like image 116
BMitch Avatar answered Oct 15 '22 06:10

BMitch