Browse code

Update links and host integration documentation

Michael Crosby authored on 2013/10/31 03:59:05
Showing 2 changed files
... ...
@@ -14,12 +14,16 @@ Building a redis container to link as a child of our web application.
14 14
 Building the redis container
15 15
 ----------------------------
16 16
 
17
-We will use a pre-build version of redis from the index under 
18
-the name ``crosbymichael/redis``.  If you are interested in the 
19
-Dockerfile that was used to build this container here it is.
17
+Lets build a redis image with the following Dockerfile.
20 18
 
21 19
 .. code-block:: bash
22
-    
20
+
21
+    git clone https://github.com/antirez/redis.git
22
+    cd redis
23
+    git checkout 2.6
24
+
25
+    # Save this Dockerfile to the root of the redis repository.  
26
+
23 27
     # Build redis from source
24 28
     # Make sure you have the redis source code checked out in
25 29
     # the same directory as this Dockerfile
... ...
@@ -34,7 +38,6 @@ Dockerfile that was used to build this container here it is.
34 34
     ADD . /redis
35 35
 
36 36
     RUN (cd /redis && make)
37
-    RUN (cd /redis && make test)
38 37
 
39 38
     RUN mkdir -p /redis-data
40 39
     VOLUME ["/redis-data"]
... ...
@@ -43,6 +46,9 @@ Dockerfile that was used to build this container here it is.
43 43
     ENTRYPOINT ["/redis/src/redis-server"]
44 44
     CMD ["--dir", "/redis-data"]
45 45
 
46
+    # docker build our new redis image from source
47
+    docker build -t redis-2.6 .
48
+
46 49
 
47 50
 We need to ``EXPOSE`` the default port of 6379 so that our link knows what ports 
48 51
 to connect to our redis container on.  If you do not expose any ports for the
... ...
@@ -54,31 +60,28 @@ Run the redis container
54 54
 
55 55
 .. code-block:: bash
56 56
     
57
-    docker run -d -e PASSWORD=docker -name redis crosbymichael/redis --requirepass=docker
57
+    docker run -d -e PASSWORD=docker -name redis redis-2.6 --requirepass docker
58 58
  
59
-This will run our redis container using the default port of 6379 and using docker 
60
-as password to secure our service.  By specifying the ``-name`` flag on run 
61
-we will assign the name ``redis`` to this container. 
62
-We can issue all the commands that you would expect; start, stop, attach, using the name.
63
-The name also allows us to link other containers into this one.  If you do not specify a 
64
-name on docker run, docker will automatically generate a name for your container. 
59
+This will run our redis container wit the password docker 
60
+to secure our service.  By specifying the ``-name`` flag on run 
61
+we will assign the name ``redis`` to this container.  If we do not specify a name  for 
62
+our container via the ``-name`` flag docker will automatically generate a name for us.
63
+We can issue all the commands that you would expect; start, stop, attach, using the name for our container.
64
+The name also allows us to link other containers into this one.
65 65
 
66 66
 Linking redis as a child
67 67
 ------------------------
68 68
 
69 69
 Next we can start a new web application that has a dependency on redis and apply a link 
70
-to connect both containers.  If you noticed when running our redis service we did not use
71
-the ``-p`` option to publish the redis port to the host system.  Redis exposed port 6379
72
-but we did not publish the port.  This allows docker to prevent all network traffic to
73
-the redis container except when explicitly specified within a link.  This is a big win
74
-for security.  
75
-
70
+to connect both containers.  If you noticed when running our redis server we did not use
71
+the ``-p`` flag to publish the redis port to the host system.  Redis exposed port 6379 via the Dockerfile 
72
+and this is all we need to establish a link.
76 73
 
77 74
 Now lets start our web application with a link into redis.
78 75
 
79 76
 .. code-block:: bash
80 77
    
81
-    docker run -t -i -link /redis:db -name webapp ubuntu bash
78
+    docker run -t -i -link redis:db -name webapp ubuntu bash
82 79
 
83 80
     root@4c01db0b339c:/# env
84 81
 
... ...
@@ -101,22 +104,25 @@ Now lets start our web application with a link into redis.
101 101
 
102 102
 
103 103
 When we inspect the environment of the linked container we can see a few extra environment 
104
-variables have been added.  When you specified ``-link /redis:db`` you are telling docker
105
-to link the container named ``/redis`` into this new container with the alias ``db``.  
104
+variables have been added.  When you specified ``-link redis:db`` you are telling docker
105
+to link the container named ``redis`` into this new container with the alias ``db``.  
106 106
 Environment variables are prefixed with the alias so that the parent container can access
107
-network and environment information from the child.
107
+network and environment information from the containers that are linked into it.
108 108
 
109 109
 .. code-block:: bash
110 110
 
111 111
     # The name of the child container
112 112
     DB_NAME=/webapp/db
113
+
113 114
     # The default protocol, ip, and port of the service running in the container
114 115
     DB_PORT=tcp://172.17.0.8:6379
116
+
115 117
     # A specific protocol, ip, and port of various services
116 118
     DB_PORT_6379_TCP=tcp://172.17.0.8:6379
117 119
     DB_PORT_6379_TCP_PROTO=tcp
118 120
     DB_PORT_6379_TCP_ADDR=172.17.0.8
119 121
     DB_PORT_6379_TCP_PORT=6379
122
+
120 123
     # Get environment variables of the container 
121 124
     DB_ENV_PASSWORD=dockerpass
122 125
 
... ...
@@ -13,113 +13,47 @@ You can use your Docker containers with process managers like ``upstart``,
13 13
 Introduction
14 14
 ------------
15 15
 
16
+If you want a process manager to manage your containers you will need to run
17
+the docker daemon with the ``-r=false`` so that docker will not automatically 
18
+restart your containers when the host is restarted.  
19
+
16 20
 When you have finished setting up your image and are happy with your
17 21
 running container, you may want to use a process manager to manage
18
-it. To help with this, we provide a simple image: ``creack/manager:min``
19
-
20
-This image takes the container ID as parameter. We also can specify
21
-the kind of process manager and metadata like *Author* and
22
-*Description*. The output will will be text suitable for a
23
-configuration file, echoed to stdout. It is up to you to create the
24
-.conf file (for `upstart
25
-<http://upstart.ubuntu.com/cookbook/#job-configuration-file>`_) or
26
-.service file (for `systemd
27
-<http://0pointer.de/public/systemd-man/systemd.service.html>`_) and
28
-put it in the right place for your system.
29
-
30
-Usage
31
-
32
-.. code-block:: bash
33
-
34
-   docker run creack/manager:min [OPTIONS] <container id>
35
-
36
-.. program:: docker run creack/manager:min
22
+it.  When your run ``docker start -a`` docker will automatically attach 
23
+to the process and forward all signals so that the process manager can 
24
+detect when a container stops and correctly restart it.  
37 25
 
38
-.. cmdoption:: -a="<none>" 
26
+Here are a few sample scripts for systemd and upstart to integrate with docker.
39 27
 
40
-   Author of the image
41 28
 
42
-.. cmdoption:: -d="<none>"
43
-
44
-   Description of the image
45
-
46
-.. cmdoption:: -t="upstart" 
47
-
48
-   Type of manager requested: ``upstart`` or ``systemd``
49
-
50
-Example Output
51
-..............
29
+Sample Upstart Script
30
+---------------------
52 31
 
53 32
 .. code-block:: bash
54 33
 
55
-   docker run creack/manager:min -t="systemd" b28605f2f9a4
56
-   [Unit]
57
-   	Description=<none>
58
-   	Author=<none>
59
-   	After=docker.service
60
-
61
-   [Service]
62
-   	Restart=always
63
-   	ExecStart=/usr/bin/docker start -a b28605f2f9a4
64
-   	ExecStop=/usr/bin/docker stop -t 2 b28605f2f9a4
65
-
66
-   [Install]
67
-   	WantedBy=local.target
34
+   description "Redis container"
35
+   author "Me"
36
+   start on filesystem and started lxc-net and started docker
37
+   stop on runlevel [!2345]
38
+   respawn
39
+   exec docker start -a 0a7e070b698b
68 40
 
69 41
 
70
-
71
-Development
72
-
73
-The image ``creack/manager:min`` is a ``busybox`` base with the
74
-compiled binary of ``manager.go`` as the :ref:`Entrypoint
75
-<entrypoint_def>`.  It is meant to be light and fast to download.
76
-
77
-If you would like to change or add things, you can download the full
78
-``creack/manager`` repository that contains ``creack/manager:min`` and
79
-``creack/manager:dev``.
80
-
81
-The Dockerfiles and the sources are available in
82
-`/contrib/host_integration
83
-<https://github.com/dotcloud/docker/tree/master/contrib/host_integration>`_.
84
-
85
-
86
-Upstart
87
-
88
-Upstart is the default process manager. The generated script will
89
-start the container after the ``docker`` daemon. If the container
90
-dies, it will respawn.  Start/Restart/Stop/Reload are
91
-supported. Reload will send a SIGHUP to the container.
92
-
93
-Example (``upstart`` on Debian)
94
-...............................
42
+Sample systemd Script
43
+---------------------
95 44
 
96 45
 .. code-block:: bash
97 46
 
98
-   CID=$(docker run -d creack/firefo-vnc)
99
-   docker run creack/manager:min -a 'Guillaume J. Charmes <guillaume@dotcloud.com>' -d 'Awesome Firefox in VLC' $CID > /etc/init/firefoxvnc.conf
100
-
101
-You can now ``start firefoxvnc`` or ``stop firefoxvnc`` and if the container
102
-dies for some reason, upstart will restart it.
103
-
104
-Systemd
47
+    [Unit]
48
+    Description=Redis container
49
+    Author=Me
50
+    After=docker.service
105 51
 
106
-In order to generate a systemd script, we need to use the ``-t``
107
-option. The generated script will start the container after docker
108
-daemon. If the container dies, it will respawn.
109
-``Start/Restart/Reload/Stop`` are supported.
110
-
111
-Example (``systemd`` on Fedora)
112
-...............................
113
-
114
-.. code-block:: bash
52
+    [Service]
53
+    Restart=always
54
+    ExecStart=/usr/bin/docker start -a 0a7e070b698b
55
+    ExecStop=/usr/bin/docker stop -t 2 0a7e070b698b
115 56
 
116
-   CID=$(docker run -d creack/firefo-vnc)
117
-   docker run creack/manager:min -t systemd -a 'Guillaume J. Charmes <guillaume@dotcloud.com>' -d 'Awesome Firefox in VLC' $CID > /usr/lib/systemd/system/firefoxvnc.service
57
+    [Install]
58
+    WantedBy=local.target
118 59
 
119
-You can now run ``systemctl start firefoxvnc`` or ``systemctl stop
120
-firefoxvnc`` and if the container dies for some reason, ``systemd``
121
-will restart it.