2013-09-12 06:50:26 +00:00
|
|
|
:title: Host Integration
|
|
|
|
:description: How to generate scripts for upstart, systemd, etc.
|
|
|
|
:keywords: systemd, upstart, supervisor, docker, documentation, host integration
|
|
|
|
|
2013-10-09 19:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
Host Integration
|
|
|
|
================
|
|
|
|
|
|
|
|
You can use your Docker containers with process managers like ``upstart``,
|
|
|
|
``systemd`` and ``supervisor``.
|
|
|
|
|
2013-09-12 06:50:26 +00:00
|
|
|
Introduction
|
2013-10-09 19:31:40 +00:00
|
|
|
------------
|
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
If you want a process manager to manage your containers you will need to run
|
|
|
|
the docker daemon with the ``-r=false`` so that docker will not automatically
|
|
|
|
restart your containers when the host is restarted.
|
|
|
|
|
2013-10-09 19:31:40 +00:00
|
|
|
When you have finished setting up your image and are happy with your
|
|
|
|
running container, you may want to use a process manager to manage
|
2013-10-30 18:59:05 +00:00
|
|
|
it. When your run ``docker start -a`` docker will automatically attach
|
|
|
|
to the process and forward all signals so that the process manager can
|
|
|
|
detect when a container stops and correctly restart it.
|
2013-09-12 06:50:26 +00:00
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
Here are a few sample scripts for systemd and upstart to integrate with docker.
|
2013-09-12 06:50:26 +00:00
|
|
|
|
2013-10-09 19:31:40 +00:00
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
Sample Upstart Script
|
|
|
|
---------------------
|
2013-10-09 19:31:40 +00:00
|
|
|
|
2013-11-13 18:34:34 +00:00
|
|
|
In this example we've already created a container to run Redis with an id of
|
|
|
|
0a7e070b698b. To create an upstart script for our container, we create a file
|
|
|
|
named ``/etc/init/redis.conf`` and place the following into it:
|
|
|
|
|
2013-10-09 19:31:40 +00:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
description "Redis container"
|
|
|
|
author "Me"
|
|
|
|
start on filesystem and started lxc-net and started docker
|
|
|
|
stop on runlevel [!2345]
|
|
|
|
respawn
|
2013-11-13 18:34:34 +00:00
|
|
|
script
|
|
|
|
# Wait for docker to finish starting up first.
|
|
|
|
FILE=/var/run/docker.sock
|
|
|
|
while [ ! -e $FILE ] ; do
|
|
|
|
inotifywait -t 2 -e create $(dirname $FILE)
|
|
|
|
done
|
|
|
|
/usr/bin/docker start -a 0a7e070b698b
|
|
|
|
end script
|
|
|
|
|
|
|
|
Next, we have to edit the docker upstart script (``/etc/init/docker.conf``)
|
|
|
|
so that we run docker with ``-r=false``. In this example, we also ensure
|
|
|
|
that docker will start running before *redis* is started.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
description "Docker daemon"
|
|
|
|
|
|
|
|
start on filesystem and started lxc-net
|
|
|
|
start on (starting redis)
|
|
|
|
stop on runlevel [!2345]
|
|
|
|
|
|
|
|
respawn
|
|
|
|
|
|
|
|
script
|
|
|
|
/usr/bin/docker -d -r=false
|
|
|
|
end script
|
2013-09-12 06:50:26 +00:00
|
|
|
|
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
Sample systemd Script
|
|
|
|
---------------------
|
2013-09-12 06:50:26 +00:00
|
|
|
|
2013-10-09 19:31:40 +00:00
|
|
|
.. code-block:: bash
|
2013-09-12 06:50:26 +00:00
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
[Unit]
|
|
|
|
Description=Redis container
|
|
|
|
Author=Me
|
|
|
|
After=docker.service
|
2013-10-09 19:31:40 +00:00
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
[Service]
|
|
|
|
Restart=always
|
|
|
|
ExecStart=/usr/bin/docker start -a 0a7e070b698b
|
|
|
|
ExecStop=/usr/bin/docker stop -t 2 0a7e070b698b
|
2013-09-12 06:50:26 +00:00
|
|
|
|
2013-10-30 18:59:05 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=local.target
|
2013-09-12 06:50:26 +00:00
|
|
|
|