I found that the original example wasn't starting the docker container when docker is started. So, I modified it using information I found from https://groups.google.com/forum/#!msg/docker-user/OWz8EOpiXuo/L_uxGFQuYlkJ
Also, upstart wasn't starting docker if it wasn't running ahead of time. So, I added a change to the docker upstart script to solve this.
| ... | ... |
@@ -29,6 +29,10 @@ Here are a few sample scripts for systemd and upstart to integrate with docker. |
| 29 | 29 |
Sample Upstart Script |
| 30 | 30 |
--------------------- |
| 31 | 31 |
|
| 32 |
+In this example we've already created a container to run Redis with an id of |
|
| 33 |
+0a7e070b698b. To create an upstart script for our container, we create a file |
|
| 34 |
+named ``/etc/init/redis.conf`` and place the following into it: |
|
| 35 |
+ |
|
| 32 | 36 |
.. code-block:: bash |
| 33 | 37 |
|
| 34 | 38 |
description "Redis container" |
| ... | ... |
@@ -36,7 +40,32 @@ Sample Upstart Script |
| 36 | 36 |
start on filesystem and started lxc-net and started docker |
| 37 | 37 |
stop on runlevel [!2345] |
| 38 | 38 |
respawn |
| 39 |
- exec docker start -a 0a7e070b698b |
|
| 39 |
+ script |
|
| 40 |
+ # Wait for docker to finish starting up first. |
|
| 41 |
+ FILE=/var/run/docker.sock |
|
| 42 |
+ while [ ! -e $FILE ] ; do |
|
| 43 |
+ inotifywait -t 2 -e create $(dirname $FILE) |
|
| 44 |
+ done |
|
| 45 |
+ /usr/bin/docker start -a 0a7e070b698b |
|
| 46 |
+ end script |
|
| 47 |
+ |
|
| 48 |
+Next, we have to edit the docker upstart script (``/etc/init/docker.conf``) |
|
| 49 |
+so that we run docker with ``-r=false``. In this example, we also ensure |
|
| 50 |
+that docker will start running before *redis* is started. |
|
| 51 |
+ |
|
| 52 |
+.. code-block:: bash |
|
| 53 |
+ |
|
| 54 |
+ description "Docker daemon" |
|
| 55 |
+ |
|
| 56 |
+ start on filesystem and started lxc-net |
|
| 57 |
+ start on (starting redis) |
|
| 58 |
+ stop on runlevel [!2345] |
|
| 59 |
+ |
|
| 60 |
+ respawn |
|
| 61 |
+ |
|
| 62 |
+ script |
|
| 63 |
+ /usr/bin/docker -d -r=false |
|
| 64 |
+ end script |
|
| 40 | 65 |
|
| 41 | 66 |
|
| 42 | 67 |
Sample systemd Script |