Deploy Drupal with MySQL in Docker Container

Vineet Kumar
2 min readJun 19, 2020

FIRST METHOD

Before we install Drupal, we need to deploy MySQL. This is easily done with Docker by running the following command. In this command, replace “MYSQL-NAME” with a name for your MySQL Docker container. Also, replace “MYSQL-PASSWORD” with a new password for the container’s MySQL instance. Record both of these for later.

docker run --name MYSQL-NAME -e MYSQL_ROOT_PASSWORD=MYSQL-PASSWORD -d mysql:latest

Deploying and Configuring Drupal with Docker

Our next step is to deploy a Drupal Docker container, connect it to your MySQL container, and finish configuring Drupal. Follow these steps.

  1. Run the following command. Replace “DRUPAL-NAME” with a name for your Drupal container. Replace “MYSQL-NAME” and “MYSQL-PASSWORD” with the values you used for your MySQL Docker container in the previous section.
  • docker run --name DRUPAL-NAME --link MYSQL-NAME:mysql -p 8080:80 -e MYSQL_USER=root -e MYSQL_PASSWORD=MYSQL-PASSWORD -d drupal
  1. Go to http://YOUR.VPS.IP:8080/ in your web browser. Replace “YOUR.VPS.IP” with the IP address of your virtual server.
  2. Follow the on-screen instructions to configure Drupal.
  1. When you reach Set up database, click ADVANCED OPTIONS.
  2. In the ADVANCED OPTIONS section, for Database name, enter “drupal”.
  3. For Database username, enter “root”.
  4. For Database host, enter the value of MYSQL-NAME for your MySQL container.
  5. For Database password, enter the value of MYSQL-PASSWORD for your MySQL container.
  6. Continue with the Drupal setup.

SECOND METHOD(useful when you have already images of deployed application):

1. Create a network: docker network create netw
2. Run Mariadb on Docker with created docker network:
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 --net=netw -d mariadb:latest
3. Run Drupal with same network :
docker run --name DRUPAL -p 8080:80 --net=netw -d drupal:<any_version>
4. Remain steps for configure Drupal will be the same as above.

Next Steps

Drupal is a flexible system. There are a lot of options for configuring your new site. Visit the Get Started with Drupal guide for more ideas on where to go next. Once you have configured Drupal and installed the plugins and themes needed to get your new website running, you can save a snapshot of your Drupal Docker container for redeployment. This can be used for quick backups, horizontal scaling, or even blue-green deployment strategies.
Follow more drupal with dokcer : https://hub.docker.com/_/drupal/

ENJOY.

--

--