Docker

Configure the Docker Daemon With systemd

Docker Daemon is a core part of Docker that is managed and operates on service. Docker Daemon is referred to as a backend process that manages and runs the Docker containers and other components on a single host. The Docker Daemon gets commands from the client through rest APIs and runs or operates containers.

This write-up will demonstrate how to configure Daemon with systemd.

How to Configure Daemon with systemd?

Most of the Daemon settings are configured in the “daemon.json” file. But sometimes, when users install Docker without a package manager. Then, users may be required to configure Docker or some services to systemd. The systemd is a Linux command line utility utilized for configuring and managing the services. It manages all Linux processes and services automatically from system boot to shut down.

Docker Daemon utilizes some environment variables that cannot be directly configured in the daemon.json files, such as HTTP_PROXY, HTTPS_PROXY, and NO_PROXY. For this purpose, you are required to configure these services into the systemd service file of Docker.

To manually configure or customize some Daemon configurations with systemd, go through the listed steps.

Step 1: Create systemd Unit file

First, create a subdirectory in the “systemd” directory to configure the docker service. Here the “-p” option is used to create the sub-directories. If directories are already created, it does not show any effect or error:

sudo mkdir -p /etc/systemd/system/docker.service.d

 

Step 2: Make File to Configure HTTP Proxy Settings

Next, make a new file “http-proxy.conf” by utilizing the nano text editor:

sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf

 

Paste the following environment variables or services into the file. For instance, we have configured HTTP_PROXY, HTTPS_PROXY, and NO_PROXY:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80"
Environment="HTTPS_PROXY=https://proxy.example.com:443"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"

 

Press “CTRL+O” to save changes and “CTRL+X” to exit the editor:

Step 3: Restart Docker

After that, reload the Docker. For this purpose, first, flush the changes and reload the Daemon using the mentioned command:

sudo systemctl daemon-reload

 

After that, restart the Docker through the “systemctl restart docker” command:

sudo systemctl restart docker

 

Step 4: Verification

For verification, whether the environment variables are configured or not, utilize the below command. Here “–property” option filters only Environment configurations for Docker:

sudo systemctl show --property=Environment docker

 

That is all about configuring the Daemon with systemd.

Conclusion

Some configuration settings are required to be set manually, such as the user’s proxy information that cannot be directly set in the daemon.json file. So, you are required to configure these settings with systemd. To do so, first, create a Docker service directory in the systemd directory and create a new file in the service directory of Docker named “http-proxy.conf” and add the proxy setting you are required to configure. Then, reload and restart the Daemon and Docker. This write-up has illustrated how to configure the Daemon with systems.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.