Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit c811821

Browse files
committed
ISSUE 60: Revised instructions on data volume usage.
1 parent 86dd6b4 commit c811821

File tree

1 file changed

+99
-16
lines changed

1 file changed

+99
-16
lines changed

README.md

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $ docker run -d \
4040
--env "SERVICE_UNIT_INSTANCE=1" \
4141
--env "APACHE_SERVER_NAME=app-1.local" \
4242
--env "DATE_TIMEZONE=UTC" \
43-
-v /var/services-data/apache-php/app-1:/var/www/app \
43+
-v /var/www/app \
4444
jdeathe/centos-ssh-apache-php-fcgi:latest
4545
```
4646

@@ -63,6 +63,14 @@ To verify the container is initialised and running successfully by inspecting th
6363
$ docker logs apache-php.app-1.1.1
6464
```
6565

66+
The Apache data is persistent across container restarts by setting the data directory ```/var/www/app``` as a data volume. No name or docker_host path was specified so Docker will give it a unique name and store it in ```/var/lib/docker/volumes/```; to find out where the data is stored on the Docker host you can use ```docker inspect```.
67+
68+
```
69+
$ docker inspect \
70+
--format '{{ json (index .Mounts 0).Source }}' \
71+
apache-php.app-1.1.1
72+
```
73+
6674
On first run, the bootstrap script, ([/etc/apache-bootstrap](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/apache-bootstrap)), will check if the DocumentRoot directory is empty and, if so, will populate it with the example app scripts and VirtualHost configuration files. If you place your own app in this directory it will not be overwritten but you must ensure to include at least a vhost.conf file and, if enabling SSL a vhost-ssl.conf file too.
6775

6876
The ```apachectl``` command can be accessed as follows.
@@ -75,28 +83,107 @@ $ docker exec -it apache-php.app-1.1.1 apachectl -h
7583

7684
### (Optional) Configuration Data Volume
7785

78-
Create a "data volume" for configuration, this allows you to share the same configuration between multiple docker containers and, by mounting a host directory into the data volume you can override the default configuration files provided.
86+
A configuration "data volume" allows you to share the same configuration files between multiple docker containers. Docker mounts a host directory into the data volume allowing you to edit the default configuration files and have those changes persist.
7987

80-
Make a directory on the docker host for storing container configuration files. This directory needs to contain everything from the directory [etc/services-config](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config)
88+
Each service that requires a common set of configuration files could use a single Configuration Volume as illustrated in the following diagram:
8189

8290
```
83-
$ mkdir -p /etc/services-config/apache-php.app-1.1.1
91+
+---------------------------------------------------+
92+
| (Docker Host system) |
93+
| |
94+
| /var/lib/docker/volumes/<volume-name>/_data |
95+
| + |
96+
| | |
97+
| +============*===========+ |
98+
| | Configuration Volume | |
99+
| | Service Container | |
100+
| +============*===========+ |
101+
| | |
102+
| +---------------*---------------+ |
103+
| | | | |
104+
| +=====*=====+ +=====*=====+ +=====*=====+ |
105+
| | Service | | Service | | Service | |
106+
| | Container | | Container | | Container | |
107+
| | (1) | | (2) | | (n) | |
108+
| +===========+ +===========+ +===========+ |
109+
+---------------------------------------------------+
84110
```
85111

86-
Create the data volume, mounting our docker host's configuration directory to */etc/services-config/ssh* in the docker container. Docker will pull the busybox:latest image if you don't already have it available locally.
112+
#### Standard data volume container
113+
114+
Naming of the container's volume is optional, it is possible to leave the naming up to Docker by simply specifying the container path only.
87115

88116
```
89117
$ docker run \
90118
--name volume-config.apache-php.app-1.1.1 \
91-
-v /etc/services-config/ssh.pool-1/ssh:/etc/services-config/ssh \
92-
-v /etc/services-config/apache-php.app-1.1.1/supervisor:/etc/services-config/supervisor \
93-
-v /etc/services-config/apache-php.app-1.1.1/httpd:/etc/services-config/httpd \
94-
-v /etc/services-config/apache-php.app-1.1.1/ssl/certs:/etc/services-config/ssl/certs \
95-
-v /etc/services-config/apache-php.app-1.1.1/ssl/private:/etc/services-config/ssl/private \
96-
busybox:latest \
119+
-v /etc/services-config \
120+
jdeathe/centos-ssh-apache-php-fcgi:latest \
97121
/bin/true
98122
```
99123

124+
To identify the docker host directory path to the volume within the container ```volume-config.apache-php.app-1.1.1``` you can use ```docker inspect``` to view the Mounts.
125+
126+
```
127+
$ docker inspect \
128+
--format '{{ json (index .Mounts 0).Source }}' \
129+
volume-config.apache-php.app-1.1.1
130+
```
131+
132+
#### Named data volume container
133+
134+
To create a named data volume, mounting our docker host's configuration directory /var/lib/docker/volumes/volume-config.apache-php.app-1.1.1 to /etc/services-config in the docker container use the following run command. Note that we use the same image as for the application container to reduce the number of images/layers required.
135+
136+
```
137+
$ docker run \
138+
--name volume-config.apache-php.app-1.1.1 \
139+
-v volume-config.apache-php.app-1.1.1:/etc/services-config \
140+
jdeathe/centos-ssh-apache-php-fcgi:latest \
141+
/bin/true
142+
```
143+
144+
##### Populating Named configuration data volumes
145+
When using named volumes the directory path from the docker host mounts the path on the container so we need to upload the configuration files. The simplest method of achieving this is to upload the contents of the [etc/services-config](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/) directory using ```docker cp```.
146+
147+
```
148+
$ docker cp \
149+
./etc/services-config/. \
150+
volume-config.apache-php.app-1.1.1:/etc/services-config
151+
```
152+
153+
If you don't have a copy of the required configuration files locally you can run a temporary container as the source of the configuration files and use `docker cp` to stream the files into the named data volume container.
154+
155+
```
156+
$ docker run -d \
157+
--name apache-php.tmp \
158+
jdeathe/centos-ssh-apache-php-fcgi:latest \
159+
/bin/sh -c 'while true; do echo -ne .; sleep 1; done';
160+
&& docker cp \
161+
apache-php.tmp:/etc/services-config/. - | \
162+
docker cp - \
163+
volume-config.apache-php.app-1.1.1:/etc/services-config
164+
&& docker rm -f apache-php.tmp
165+
```
166+
167+
#### Editing configuration
168+
169+
To make changes to the configuration files you need a running container that uses the volumes from the configuration volume. To edit a single file you could use the following, where <path_to_file> can be one of the [required configuration files](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/README.md#required-configuration-files), or you could run a ```bash``` shell and then make the changes required using ```vi```. On exiting the container it will be removed since we specify the ```--rm``` parameter.
170+
171+
```
172+
$ docker run --rm -it \
173+
--volumes-from volume-config.apache-php.app-1.1.1 \
174+
jdeathe/centos-ssh-apache-php-fcgi:latest \
175+
vi /etc/services-config/<path_to_file>
176+
```
177+
178+
##### Required configuration files
179+
180+
The following configuration files are required to run the application container and should be located in the directory /etc/services-config/.
181+
182+
- [httpd/conf/httpd.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/conf/httpd.conf)
183+
- [httpd/conf.d/php.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/conf.d/php.conf)
184+
- [httpd/conf.d/ssl.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/conf.d/ssl.conf)
185+
- [supervisor/supervisord.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/supervisor/supervisord.conf)
186+
100187
### Running
101188

102189
To run the a docker container from this image you can use the included [run.sh](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.sh) and [run.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.conf) scripts. The helper script will stop any running container of the same name, remove it and run a new daemonised container on an unspecified host port. Alternatively you can use the following methods to make the http service available on ports 8080 of the docker host.
@@ -276,7 +363,7 @@ Use the ```SERVICE_USER```, ```SERVICE_USER_GROUP``` and ```SERVICE_USER_PASSWOR
276363

277364
### Custom Configuration
278365

279-
If using the optional data volume for container configuration you are able to customise the configuration. In the following examples your custom docker configuration files should be located on the Docker host under the directory ```/etc/service-config/<container-name>/``` where ```<container-name>``` should match the applicable container name such as "apache-php.app-1.1.1" in the examples.
366+
If using the optional data volume for container configuration you are able to customise the configuration. In the following examples your custom docker configuration files should be located on the Docker host under the directory ```/var/lib/docker/volumes/<volume-name>/``` where ```<container-name>``` should match the applicable container name such as "apache-php.app-1.1.1" if using named volumes or will be an ID generated automatically by Docker. To identify the correct path on the Docker host use the ```docker inspect``` command.
280367

281368
#### [httpd/apache-bootstrap.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/apache-bootstrap.conf)
282369

@@ -305,7 +392,3 @@ To override the SSLCertificateKeyFile add it to your config directory using the
305392
#### [supervisor/supervisord.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/supervisor/supervisord.conf)
306393

307394
The supervisor service's configuration can also be overridden by editing the custom supervisord.conf file. It shouldn't be necessary to change the existing configuration here but you could include more [program:x] sections to run additional commands at startup.
308-
309-
### Apache DocumentRoot - Data Directory
310-
311-
In the previous example Docker run commands we mapped the Docker host directory ```/var/services-data/apache-php/app-1``` to ```/var/www/app``` in the Docker container, where ```/var/services-data/``` is the directory used to store persistent files and the subdirectory is used by an individual app's named container(s), ```apache-php.app-1.1.1```, in the previous examples.

0 commit comments

Comments
 (0)