Drupal 8 is not new now and most developers have started using Docker for local development. However, few developers still struggle to setup Docker locally. There are tons of documents available on the Internet which describe how to set up a local Docker + Drupal development environment. They are really helpful but most of them come with their own custom images. Considering folks who are new to Docker find this documentation complicated sometimes because to run Docker locally requires a lot of configurations. On top of that, there are multiple docker images available on Web, and developers who want to use docker in existing projects can't finalize what is the right Docker image for their project.
If an existing project development is already happening without Docker (maybe using XAMPP, WAMP, Acquia Dev Desktop or Vagrant etc.) then developers don't want to spend much time on setting up it on Docker. They want to minimize the setup time and to do that they look for any relevant Docker image. Sometimes they get it easily but most of the time they find that there are some extra modules/configurations/components/libraries that are not needed in their project. Hence, they may look for plain PHP, Apache and MySql image that they can update as per their requirements.
- Create separate containers for PHP, MySQL, and Apache.
- Manage version for all the containers separately.
- Whatever the libraries are needed, just add the same in the individual docker file.
- Setup the local repository, error logs etc. path in the docker file itself.
- Docker
- Docker-Compose - Needed for Linux
- Understanding of Composer
- Clone this repository and run the below command:
docker-compose up -d
- If everthing goes well, you will see below message:
Creating php ... done Creating mysql ... done Creating apache ... done
- To see docker images run below command:
docker ps
You will see individual containers for PHP, MySql and Apache as shown below:
CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES |
---|---|---|---|---|---|---|
09f51b5f330b | dockerize-existing-drupal-project_apache | "httpd-foreground" | 32 seconds ago | Up 30 seconds | 0.0.0.0:80->80/tcp | apache |
8294e1800058 | dockerize-existing-drupal-project_php | "docker-php-entrypoi…" | 33 seconds ago | Up 31 seconds | 9000/tcp | php |
d8b2cbac5695 | mysql:8.0.0 | "docker-entrypoint.s…" | 33 seconds ago | Up 31 seconds | 0.0.0.0:3306->3306/tcp | mysql |
- Now hit the http://localhost:80 in browser to ensure setup is successful. Along with the below output, you will also see phpinfo() output.
Congratulations!! Docker setup connection is successful. Checking MySQL integration with php. MySql connection is successful!
- With the current setup you will get below versions but you can change it anytime in .env file.
PHP Version = 7.3.11 APACHE_VERSION = 2.4.41 MYSQL_VERSION = 8.0.0
- Now put your codebase inside
docroot
folder that is pointed to/var/www/html
in the PHP container. You can also use Drupal Composer Project to create a Drupal installation from scratch.
You can jump to command line prompt of PHP container using below docker command:
docker exec -it 8294e1800058 /bin/sh
8294e1800058
is PHP container id as shown in the above table.
-
Since the Drush and composer are already part of PHP docker image, you can simply import the database using drush.
-
This way the basic setup is done and you can change the composer file accordingly. In case any additional PHP library is needed, update the PHP docker file and rebuild the PHP Docker image.
--WIP---
--WIP---
docker-compose up
Start all the containers.docker-compose down
Stop all the containers.docker system prune -a
Delete all the docker images.docker ps
See all active containers.
https://itnext.io/local-drupal-8-development-with-docker-ed25910cfce2