Difficulty: Beginner
Estimated Time: 10 minutes

There are many ways to manage the lifetime of a container. Many times this comes down to the complexity of the application or system being deployed.

Other times, you need to bootstrap a container to launch the rest of your system.

In this scenario, we'll explain how to use Systemd to launch and manage containers when your system boots. This environment is running a CoreOS instance, however, applies to other Systemd based OSes.

In this scenario we explored how to use Systemd to manage the starting Docker containers.

You can view the unit file used at https://gist.github.com/BenHall/b31e7778dbc4ed612dbcf40acccbf1df

Let everyone know about your success:

Don’t stop now! The next scenario will take about 20 minutes to complete. You can pause and come back at any time.

Start Docker Containers on Boot with Systemd

Step 1 of 4

Create Systemd Unit File

With Systemd, all services have a unit file. A unit file defines how Systemd should manage the service. It will generally include:

  • System dependencies and services which must be running

  • Tasks to perform before launching

  • How to start the process

  • How to stop process

  • How to restart the process if it crashes

When using Systemd to launch Docker containers the service file manages the processes via the Docker CLI. You can see the example of starting Postgres here cat postgres.service