Docker /usr/lib/systemd

Ubuntu 16.04 LTS is now available. After having made the switch from 14.04 without really looking at the changes except for the kernel number (4.x), I was pleasantly surprised by the fact that it now uses systemd.

  1. Vi /usr/lib/systemd/system/docker.service
  2. /usr/lib/systemd/system/docker.service Registry

I used this answer as a guide to help me writer a startup script for systemd to start my Jenkins container when my machine boots up. However, the script is not working. Here is the script: Unit. Actually I don't remember why I made it. Seems I was trying to setup docker daemon on a cloud instance, and this was a memo of the config inside Container Optimized Machine of Google Cloud.


Mar 09, 2019 Kubernetes version 1.13.2 We want to use systemd as cgroup driver for docker and kubelet, let’s see how to achieve that. First you need to understand what is systemd and cgroup?You can refer to this a.

Trying to setup docker to pull/push from a private registry using security, I first attempted to change the logging level to debug by adding -D in /etc/default/docker and after restarting docker noticed that no 'debug' logs were shown.
This took me a while to find out but /etc/default/docker is not used anymore.
This fact is in the /etc/default/docker file but easy to miss:
# Docker Upstart and SysVinit configuration file
#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
# Please see the documentation for 'systemd drop-ins':
# https://docs.docker.com/engine/articles/systemd/
#
# Customize location of Docker binary (especially for development testing).
#DOCKER='/usr/local/bin/docker'
# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS='--dns 8.8.8.8 --dns 8.8.4.4'
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy='http://127.0.0.1:3128/'
# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR='/mnt/bigdrive/docker-tmp'
Also, one can find out where a service file and configuration is located:
$ systemctl show --property=FragmentPath docker
FragmentPath=/usr/lib/systemd/system/docker.service
$ grep EnvironmentFile /usr/lib/systemd/system/docker.service
grep: /usr/lib/systemd/system/docker.service: No such file or directory
What the above tells us is that the docker service has no configuration file at the moment.
There are different ways to configure services in systemd. The option described below is OK but deviates from a standard systemd setup in the config location as, since this is Ubuntu, /etc/default path is used instead of /etc/sysconfig.
The first step to use a config file is to add the required informarion to the /lib/systemd/system/docker.service file by adding an EnvironmentFile attribute in the [Service] section:
$ vi /lib/systemd/system/docker.service

Vi /usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
Docker /usr/lib/systemd serverAfter=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
# see https://docs.docker.com/engine/admin/systemd
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTIONS
$DOCKER_STORAGE_OPTIONS
$DOCKER_NETWORK_OPTIONS
$BLOCK_REGISTRY
$INSECURE_REGISTRY
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0Docker /usr/lib/systemd
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
[Install]
WantedBy=multi-user.target
Now when the docker service is restarted it will use /etc/default/docker as its environment file, and pull the environment variables from it.
As such, the final step is to add the matching options in /etc/default/docker:
# Docker Upstart and SysVinit configuration file

# Customize location of Docker binary (especially for development testing).

/usr/lib/systemd/system/docker.service Registry

#DOCKER='/usr/local/bin/docker'

# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS='--dns 8.8.8.8 --dns 8.8.4.4'

# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy='http://127.0.0.1:3128/'

# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR='/mnt/bigdrive/docker-tmp'
INSECURE_REGISTRY='
DOCKER_STORAGE_OPTIONS='
DOCKER_NETWORK_OPTIONS='
BLOCK_REGISTRY='
It should work.