Skip to content

Commit bfc56d5

Browse files
authored
Merge pull request #811 from infosiftr/drupal-volumes
Add some notes about volumes in Drupal, especially updating "docker-compose.yml"
2 parents af448b9 + 7f751b9 commit bfc56d5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

drupal/content.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,41 @@ $ docker run --name some-%%REPO%% --link some-postgres:postgres -d %%REPO%%
4646
- Database name/username/password: `<details for accessing your PostgreSQL instance>` (`POSTGRES_USER`, `POSTGRES_PASSWORD`; see environment variables in the description for [`postgres`](https://registry.hub.docker.com/_/postgres/))
4747
- ADVANCED OPTIONS; Database host: `postgres` (for using the `/etc/hosts` entry added by `--link` to access the linked container's PostgreSQL instance)
4848

49+
## Volumes
50+
51+
By default, this image does not include any volumes. There is a lot of good discussion on this topic in [docker-library/drupal#3](https://github.com/docker-library/drupal/issues/3), which is definitely recommended reading.
52+
53+
There is consensus that `/var/www/html/modules`, `/var/www/html/profiles`, and `/var/www/html/themes` are things that generally ought to be volumes (and might have an explicit `VOLUME` declaration in a future update to this image), but handling of `/var/www/html/sites` is somewhat more complex, since the contents of that directory *do* need to be initialized with the contents from the image.
54+
55+
If using bind-mounts, one way to accomplish pre-seeding your local `sites` directory would be something like the following:
56+
57+
```console
58+
$ docker run --rm %%REPO%% tar -cC /var/www/html/sites . | tar -xC /path/on/host/sites
59+
```
60+
61+
This can then be bind-mounted into a new container:
62+
63+
```console
64+
$ docker run --name some-%%REPO%% --link some-postgres:postgres -d \
65+
-v /path/on/host/modules:/var/www/html/modules \
66+
-v /path/on/host/profiles:/var/www/html/profiles \
67+
-v /path/on/host/sites:/var/www/html/sites \
68+
-v /path/on/host/themes:/var/www/html/themes \
69+
%%REPO%%
70+
```
71+
72+
Another solution using Docker Volumes:
73+
74+
```console
75+
$ docker volume create %%REPO%%-sites
76+
$ docker run --rm -v %%REPO%%-sites:/temporary/sites %%REPO%% cp -aRT /var/www/html/sites /temporary/sites
77+
$ docker run --name some-%%REPO%% --link some-postgres:postgres -d \
78+
-v %%REPO%%-modules:/var/www/html/modules \
79+
-v %%REPO%%-profiles:/var/www/html/profiles \
80+
-v %%REPO%%-sites:/var/www/html/sites \
81+
-v %%REPO%%-themes:/var/www/html/themes \
82+
```
83+
4984
## %%COMPOSE%%
5085

5186
## Adding additional libraries / extensions

drupal/docker-compose.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Drupal with PostgreSQL
22
#
3-
# Access via "http://localhost:8080" (or "http://$(docker-machine ip):8080" if using docker-machine)
3+
# Access via "http://localhost:8080"
4+
# (or "http://$(docker-machine ip):8080" if using docker-machine)
45
#
56
# During initial Drupal setup,
67
# Database type: PostgreSQL
@@ -17,6 +18,14 @@ services:
1718
image: drupal:8.2-apache
1819
ports:
1920
- 8080:80
21+
volumes:
22+
- /var/www/html/modules
23+
- /var/www/html/profiles
24+
- /var/www/html/themes
25+
# this takes advantage of the feature in Docker that a new anonymous
26+
# volume (which is what we're creating here) will be initialized with the
27+
# existing content of the image at the same location
28+
- /var/www/html/sites
2029
restart: always
2130

2231
postgres:

0 commit comments

Comments
 (0)