This updates the supervisor example documentation
to use an up-to-date version of Ubuntu.
Also reduced the use of "royal We", and tweaked some
language.
Finally, added some language hints for code-highlighting.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e38678e6601cc597b621aaf3cf630419a7963ae9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -15,104 +15,140 @@ parent = "engine_admin" |
| 15 | 15 |
> - **If you don't like sudo** then see [*Giving non-root |
| 16 | 16 |
> access*](../installation/binaries.md#giving-non-root-access) |
| 17 | 17 |
|
| 18 |
-Traditionally a Docker container runs a single process when it is |
|
| 19 |
-launched, for example an Apache daemon or a SSH server daemon. Often |
|
| 20 |
-though you want to run more than one process in a container. There are a |
|
| 21 |
-number of ways you can achieve this ranging from using a simple Bash |
|
| 22 |
-script as the value of your container's `CMD` instruction to installing |
|
| 23 |
-a process management tool. |
|
| 24 |
- |
|
| 25 |
-In this example we're going to make use of the process management tool, |
|
| 26 |
-[Supervisor](http://supervisord.org/), to manage multiple processes in |
|
| 27 |
-our container. Using Supervisor allows us to better control, manage, and |
|
| 28 |
-restart the processes we want to run. To demonstrate this we're going to |
|
| 29 |
-install and manage both an SSH daemon and an Apache daemon. |
|
| 18 |
+Traditionally a Docker container runs a single process when it is launched, for |
|
| 19 |
+example an Apache daemon or a SSH server daemon. Often though you want to run |
|
| 20 |
+more than one process in a container. There are a number of ways you can |
|
| 21 |
+achieve this ranging from using a simple Bash script as the value of your |
|
| 22 |
+container's `CMD` instruction to installing a process management tool. |
|
| 23 |
+ |
|
| 24 |
+In this example you're going to make use of the process management tool, |
|
| 25 |
+[Supervisor](http://supervisord.org/), to manage multiple processes in a |
|
| 26 |
+container. Using Supervisor allows you to better control, manage, and restart |
|
| 27 |
+the processes inside the container. To demonstrate this we're going to install |
|
| 28 |
+and manage both an SSH daemon and an Apache daemon. |
|
| 30 | 29 |
|
| 31 | 30 |
## Creating a Dockerfile |
| 32 | 31 |
|
| 33 |
-Let's start by creating a basic `Dockerfile` for our |
|
| 34 |
-new image. |
|
| 32 |
+Let's start by creating a basic `Dockerfile` for our new image. |
|
| 35 | 33 |
|
| 36 |
- FROM ubuntu:13.04 |
|
| 37 |
- MAINTAINER examples@docker.com |
|
| 34 |
+```Dockerfile |
|
| 35 |
+FROM ubuntu:16.04 |
|
| 36 |
+MAINTAINER examples@docker.com |
|
| 37 |
+``` |
|
| 38 | 38 |
|
| 39 | 39 |
## Installing Supervisor |
| 40 | 40 |
|
| 41 |
-We can now install our SSH and Apache daemons as well as Supervisor in |
|
| 42 |
-our container. |
|
| 41 |
+You can now install the SSH and Apache daemons as well as Supervisor in the |
|
| 42 |
+container. |
|
| 43 | 43 |
|
| 44 |
- RUN apt-get update && apt-get install -y openssh-server apache2 supervisor |
|
| 45 |
- RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor |
|
| 44 |
+```Dockerfile |
|
| 45 |
+RUN apt-get update && apt-get install -y openssh-server apache2 supervisor |
|
| 46 |
+RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor |
|
| 47 |
+``` |
|
| 46 | 48 |
|
| 47 |
-Here we're installing the `openssh-server`, |
|
| 48 |
-`apache2` and `supervisor` |
|
| 49 |
-(which provides the Supervisor daemon) packages. We're also creating four |
|
| 50 |
-new directories that are needed to run our SSH daemon and Supervisor. |
|
| 49 |
+The first `RUN` instruction installs the `openssh-server`, `apache2` and |
|
| 50 |
+`supervisor` (which provides the Supervisor daemon) packages. The next `RUN` |
|
| 51 |
+instruction creates four new directories that are needed to run the SSH daemon |
|
| 52 |
+and Supervisor. |
|
| 51 | 53 |
|
| 52 | 54 |
## Adding Supervisor's configuration file |
| 53 | 55 |
|
| 54 |
-Now let's add a configuration file for Supervisor. The default file is |
|
| 55 |
-called `supervisord.conf` and is located in |
|
| 56 |
-`/etc/supervisor/conf.d/`. |
|
| 56 |
+Now let's add a configuration file for Supervisor. The default file is called |
|
| 57 |
+`supervisord.conf` and is located in `/etc/supervisor/conf.d/`. |
|
| 57 | 58 |
|
| 58 |
- COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
|
| 59 |
+```Dockerfile |
|
| 60 |
+COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
|
| 61 |
+``` |
|
| 59 | 62 |
|
| 60 |
-Let's see what is inside our `supervisord.conf` |
|
| 61 |
-file. |
|
| 63 |
+Let's see what is inside the `supervisord.conf` file. |
|
| 62 | 64 |
|
| 63 |
- [supervisord] |
|
| 64 |
- nodaemon=true |
|
| 65 |
+```ini |
|
| 66 |
+[supervisord] |
|
| 67 |
+nodaemon=true |
|
| 65 | 68 |
|
| 66 |
- [program:sshd] |
|
| 67 |
- command=/usr/sbin/sshd -D |
|
| 69 |
+[program:sshd] |
|
| 70 |
+command=/usr/sbin/sshd -D |
|
| 68 | 71 |
|
| 69 |
- [program:apache2] |
|
| 70 |
- command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" |
|
| 72 |
+[program:apache2] |
|
| 73 |
+command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" |
|
| 74 |
+``` |
|
| 71 | 75 |
|
| 72 |
-The `supervisord.conf` configuration file contains |
|
| 73 |
-directives that configure Supervisor and the processes it manages. The |
|
| 74 |
-first block `[supervisord]` provides configuration |
|
| 75 |
-for Supervisor itself. We're using one directive, `nodaemon` |
|
| 76 |
-which tells Supervisor to run interactively rather than |
|
| 77 |
-daemonize. |
|
| 76 |
+The `supervisord.conf` configuration file contains directives that configure |
|
| 77 |
+Supervisor and the processes it manages. The first block `[supervisord]` |
|
| 78 |
+provides configuration for Supervisor itself. The `nodaemon` directive is used, |
|
| 79 |
+which tells Supervisor to run interactively rather than daemonize. |
|
| 78 | 80 |
|
| 79 |
-The next two blocks manage the services we wish to control. Each block |
|
| 80 |
-controls a separate process. The blocks contain a single directive, |
|
| 81 |
-`command`, which specifies what command to run to |
|
| 82 |
-start each process. |
|
| 81 |
+The next two blocks manage the services we wish to control. Each block controls |
|
| 82 |
+a separate process. The blocks contain a single directive, `command`, which |
|
| 83 |
+specifies what command to run to start each process. |
|
| 83 | 84 |
|
| 84 | 85 |
## Exposing ports and running Supervisor |
| 85 | 86 |
|
| 86 |
-Now let's finish our `Dockerfile` by exposing some |
|
| 87 |
-required ports and specifying the `CMD` instruction |
|
| 88 |
-to start Supervisor when our container launches. |
|
| 87 |
+Now let's finish the `Dockerfile` by exposing some required ports and |
|
| 88 |
+specifying the `CMD` instruction to start Supervisor when our container |
|
| 89 |
+launches. |
|
| 89 | 90 |
|
| 90 |
- EXPOSE 22 80 |
|
| 91 |
- CMD ["/usr/bin/supervisord"] |
|
| 91 |
+```Dockerfile |
|
| 92 |
+EXPOSE 22 80 |
|
| 93 |
+CMD ["/usr/bin/supervisord"] |
|
| 94 |
+``` |
|
| 92 | 95 |
|
| 93 |
-Here we've exposed ports 22 and 80 on the container and we're running |
|
| 94 |
-the `/usr/bin/supervisord` binary when the container |
|
| 95 |
-launches. |
|
| 96 |
+These instructions tell Docker that ports 22 and 80 are exposed by the |
|
| 97 |
+container and that the `/usr/bin/supervisord` binary should be executed when |
|
| 98 |
+the container launches. |
|
| 96 | 99 |
|
| 97 | 100 |
## Building our image |
| 98 | 101 |
|
| 99 |
-We can now build our new image. |
|
| 102 |
+Your completed Dockerfile now looks like this: |
|
| 103 |
+ |
|
| 104 |
+```Dockerfile |
|
| 105 |
+FROM ubuntu:16.04 |
|
| 106 |
+MAINTAINER examples@docker.com |
|
| 107 |
+ |
|
| 108 |
+RUN apt-get update && apt-get install -y openssh-server apache2 supervisor |
|
| 109 |
+RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor |
|
| 110 |
+ |
|
| 111 |
+COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
|
| 112 |
+ |
|
| 113 |
+EXPOSE 22 80 |
|
| 114 |
+CMD ["/usr/bin/supervisord"] |
|
| 115 |
+``` |
|
| 116 |
+ |
|
| 117 |
+And your `supervisord.conf` file looks like this; |
|
| 118 |
+ |
|
| 119 |
+```ini |
|
| 120 |
+[supervisord] |
|
| 121 |
+nodaemon=true |
|
| 122 |
+ |
|
| 123 |
+[program:sshd] |
|
| 124 |
+command=/usr/sbin/sshd -D |
|
| 125 |
+ |
|
| 126 |
+[program:apache2] |
|
| 127 |
+command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" |
|
| 128 |
+``` |
|
| 129 |
+ |
|
| 130 |
+ |
|
| 131 |
+You can now build the image using this command; |
|
| 100 | 132 |
|
| 101 |
- $ docker build -t <yourname>/supervisord . |
|
| 133 |
+```bash |
|
| 134 |
+$ docker build -t mysupervisord . |
|
| 135 |
+``` |
|
| 102 | 136 |
|
| 103 |
-## Running our Supervisor container |
|
| 137 |
+## Running your Supervisor container |
|
| 104 | 138 |
|
| 105 |
-Once we've got a built image we can launch a container from it. |
|
| 139 |
+Once you have built your image you can launch a container from it. |
|
| 106 | 140 |
|
| 107 |
- $ docker run -p 22 -p 80 -t -i <yourname>/supervisord |
|
| 108 |
- 2013-11-25 18:53:22,312 CRIT Supervisor running as root (no user in config file) |
|
| 109 |
- 2013-11-25 18:53:22,312 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing |
|
| 110 |
- 2013-11-25 18:53:22,342 INFO supervisord started with pid 1 |
|
| 111 |
- 2013-11-25 18:53:23,346 INFO spawned: 'sshd' with pid 6 |
|
| 112 |
- 2013-11-25 18:53:23,349 INFO spawned: 'apache2' with pid 7 |
|
| 113 |
- . . . |
|
| 141 |
+```bash |
|
| 142 |
+$ docker run -p 22 -p 80 -t -i mysupervisord |
|
| 143 |
+2013-11-25 18:53:22,312 CRIT Supervisor running as root (no user in config file) |
|
| 144 |
+2013-11-25 18:53:22,312 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing |
|
| 145 |
+2013-11-25 18:53:22,342 INFO supervisord started with pid 1 |
|
| 146 |
+2013-11-25 18:53:23,346 INFO spawned: 'sshd' with pid 6 |
|
| 147 |
+2013-11-25 18:53:23,349 INFO spawned: 'apache2' with pid 7 |
|
| 148 |
+... |
|
| 149 |
+``` |
|
| 114 | 150 |
|
| 115 |
-We've launched a new container interactively using the `docker run` command. |
|
| 151 |
+You launched a new container interactively using the `docker run` command. |
|
| 116 | 152 |
That container has run Supervisor and launched the SSH and Apache daemons with |
| 117 | 153 |
it. We've specified the `-p` flag to expose ports 22 and 80. From here we can |
| 118 | 154 |
now identify the exposed ports and connect to one or both of the SSH and Apache |