The recent release of Ubuntu (15.04) introduced Systemd as a replacement for Upstart. Systemd is the init system for Linux and starts all the required services.
With new systems comes new approaches. One of the main activities is customising the launch of services such as Docker.
With Upstart, extra Docker launch parameters like storage devices are set in /etc/default/docker
. An example isĀ 'DOCKER_OPTS="-H unix:///var/run/docker.sock"'
With Systemd, you need to update Docker’s service file to use the extra parameters via a EnvironmentFile.
Steps
1) Docker’s system file can located at /lib/systemd/system/docker.service
2) The ExecStart line defines how to start a service. By default this is ExecStart=/usr/bin/docker -d -H fd://
3) Include the line EnvironmentFile=/etc/default/docker
above ExecStart
4) Update the ExecStart to use the variable created.
ExecStart=/usr/bin/docker -d -H fd:// $DOCKER_OPTS
The complete docker.service file should look like
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] EnvironmentFile=/etc/default/docker ExecStart=/usr/bin/docker -d -H fd:// $DOCKER_OPTS MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity [Install] WantedBy=multi-user.target
When the service starts it also includes the parameters defined in /etc/default/docker
.
Two warnings:
1) If /etc/default/docker
does not exist then it will fail to start
2) Every time you upgrade Docker the docker.service file is overridden meaning you need to repeat the above steps. This is why I find it useful to keep the variables in a separate file.