Aaaaand we got an official Drupal Docker container! (I know it's sitting there since 2015-04-29 02:45:55 lol)

In case you're wondering what are these Docker containers, they're a way of simplifying our development without actually being scared of breaking something.

Also, if you want to get in the commands faster I recommend you this cheatsheet with more or less basic commands.

Start dockerizing your environment and let's ship those templates :D

Here is my version of Drupal 8 running on Docker :)


Jaypan’s picture

Is it really official? Is this something the Drupal organization has put out?

dminca’s picture

As they say in their Official Repositories Documentation:

"Docker, Inc. sponsors a dedicated team that is responsible for reviewing and publishing all Official Repositories content. This team works in collaboration with upstream software maintainers, security experts, and the broader Docker community."


New Docker users are encouraged to use the Official Repositories in their projects. These repositories have clear documentation, promote best practices, and are designed for the most common use cases. Advanced users are encouraged to review the Official Repositories as part of their Dockerfile learning process.

Jaypan’s picture

I think it would be the Docker official Drupal container then, rather than the Drupal official Docker container, as it's not offical by the Drupal organization, but rather by the Docker organization.

dminca’s picture

I think the best way to know this is to actually get confirmation from a certified Drupal staff member :)

izmeez’s picture

subscribing to follow this.

molavec’s picture

I don't understand run command:

$ docker run --name some-drupal -d drupal

where could i find more info about options and possible arguments? where is defined -d option and what is means? This is a base Docker to implement a custom docker or i could use it ? how to choose drupal 7 or 8?

Sorry, if it not the place to ask this things but I really missed.

Thanks in advance.

Shura80’s picture

Hi molavec,

to get all possible arguments just run 'docker run -help'.

In the example command, 'some-drupal' is the name you want to assign to your container and 'drupal' is the tag that will be pulled from repository to build the container (if you didn't pulled it from repository at the beginning with 'docker pull drupal' command).

To get the latest version (8) just use 'drupal' as tag.
To get the latest drupal 7 version use 'drupal:7'.
To get specific drupal 7 version use, for example, 'drupal:7.38'.

anatico’s picture


Can anyone tell me how we use the container without erasing the content of the /var/www/html folder when sharing this folder?

docker run -d -P -v $HOME/site/drupal8:/var/www/html --name drupal8 drupal

I have tried this but, as it is a mountpoint, the content of the remote folder (/var/www/html) is replaced by the content of the host folder which is nothing ($HOME/site/drupal8).

Thank you!

paul_ck’s picture

This is normal behaviour - docker does not "merge" but replaces folder contents when mounting to an existing (container) folder.

I'm not sure what you are trying to achieve but if you really want to keep the original content, you have to use a different mount point e.g. -v $HOME/site/drupal8:/var/www/html/my-drupal8. /var/www/html will contain all original files plus a "my-drupal8" folder.

anatico’s picture

Hi paul_ck, thanks for your answer. I know it is the normal behavior of mount point. However, I don't understand how it can be useful to have a docker already with Drupal installed if when we run the machine the mount point replaces the content of the drupal folder. And if we don't share the folder with our host machine we can't edit the code. Is this a docker just to test drupal maybe?

paul_ck’s picture

tl;dr: Mount your project directory for dev, build your own docker image for production.

We use it in different ways for different purposes:
* Quick test-drive/demo: just run the container and don't mount anything
* Development: "git clone" your Drupal 8 Project to the host system and mount everything into the container. Now you can edit code and see the changes in your browser (you will likely encounter some file permission problems but nothing one can't fix)
* Production: When development is done, we push the code to git. This triggers a CI system which checks out the updated code, builds the whole stuff and "bakes" it into a production-deployable docker image (docker build -t my-fancy-drupal .).
This image is also used for functional and integration tests.

The Dockerfile basically looks like:

FROM drupal:8 # take the base image ...

[... some stuff in between ...]

ADD . /var/www/html # and add your code on top

Docker-unrelated note: Be very careful what you expose in production! Right now the default Drupal 8 setup is a security nightmare, e.g. you can access http://localhost/composer.lock which tells the whole world about your installed packages and their security issues.
I'd love to see a "web" or "public" directory with nothing but an index.php and some assets in it (see Symfony2 and most other PHP application from the 21st century).

Drupal-unrelated note: Be careful with credentials when using docker (

nidash’s picture

I was able to make this work finally, this is how i did it:

I tried with just mounting the whole drupal folder, ran into problems, so had to mount modules & themes folder seperately then worked like a charm. I also used the mysql docker container to store data. Hope this helps someone.

paul_ck’s picture

Nice write up!

The file permission/user-mapping-in-development-problem is a bit tricky. You have to take care, that sites/default/files is writable for the container user `www-data` which does not necessarily exist on the host.
Plus, all vendor/bin commands should be executed as user www-data.

A proper way of running drupal's unit tests in a running container could be:
docker exec -it drupal su -s /bin/bash -p -c "vendor/bin/phpunit -c core" www-data

Unfortunately there is no easy way yet, I guess.
User namespaces (Docker 1.10+) might be a game changer however.

nidash’s picture

I also was wondering why there is no drush or drupal console in the container..

gregsky1984’s picture

Is it really official? can't be true...

paul_ck’s picture

Everything under is considered official.

You can find the repositories of these images here:
More details about best practices and the review process of "official docker images" can be found here:

dminca’s picture

I've attached the URL to Drupal 8 on Docker

daret5893’s picture

check path docker run -d -P -v $HOME/site/drupal8:/var/www/html --name drupal8 drupal
maybe you 're wrong somewhere

dminca’s picture

The official docker container has some problems with sharing users local drupal code

nidash’s picture

Not if you mount your code as a volume..

You can also mount more than 1 volume, so you can mount modules, themes and profiles separately eg.

docker run -v /$HOME/work/admin-d8/modules:/var/www/html/modules -v /$HOME/work/admin-d8/themes:/var/www/html/themes -v /$HOME/work/admin-d8/profiles:/var/www/html/profiles -p 8080:80 --name mydrupal -d drupal:8.1.0


exhuma’s picture

I've found this container via docker hub and was trying to set it up for production. But I got stumped by the problem that I can't find a way to persist files. I've tried using a volume -v ./drupal-data:/var/www/html but that ended up with an empty /var/www folder (which is normal).

I've now later come across this thread, and looking at the comments it looks like this is an image used for drupal development. It does not look like it's meant as a production container?

If I want to publish a site based on drupal, would you recommend to:

  • derive an image from this drupal image
  • create a new image deriving from an OS base image
  • Use this image with some kind of different volume handling?

In case it's the last point: how would I achieve that?

dminca’s picture

@nidash and @exhuma they are currently having issues with volumes, as you can see from the GitHub issues raised.

chingis’s picture

Check out this open source initiative, it's a set of containers with the compose file you can use to spin up your local environment with Docker

ilcomsoft’s picture