Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download and install docker for your platform.

Running Drupal in Docker

Drupal requires MySql to function. So before deploying docker you need to deploy a docker instance of MySql/MariaDB. To deploy a MySql Instance on Docker issue the following command

docker run --name mysql -e MYSQL_ROOT_PASSWORD=yourpassword -p 3306:3306 -d mysql:latest

This will deploy the MySql Docker instance

Deploy Drupal Container

docker run --name drupal --link MYSQL-NAME:mysql -p 8000:80 -e MYSQL_USER=root -e MYSQL_PASSWORD=yourpassword -d drupal

This will deploy the Drupal container. Match the MySql credentials to the above command. You can visit the container by visiting http://localhost:8000 or http://YOUR_IP_ADDRESS:8000

In Drupal during installation go to advanced options in Database setup and set the host to the container name of mysql, which in the above case is mysql

Explanation of switches

--name=the name of the instance. You can give it any name you want
-d Run in detached mode
-p Map ports of docker container to local ports
-e Set environment Variables

If you already have images of mysql and drupal

Create a Network by issuing the following command

docker network create drupalnet
docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 --net=netw -d mysql:latest
docker run --name drupal -p 8000:80 --net=netw -d drupal:latest

This will create a Network and connect the two containers together.

For learning more about Drupal Visit Getting Started with Drupal. For more information on Drupal on Docker visit Drupal in docker hub.

Hope you find it useful

No comments:

Post a Comment

Running Drupal in Docker

I will assume that you have already installed docker. If you haven't installed docker please visit https://www.docker.com/ to download a...