Reading Time: about 5 minutes

Drupal is a powerful, popular content management system and web application framework written in PHP. It is extensible through plugins and a powerful API. It can power websites ranging from personal blogs to business collaboration applications. It has a flexible database interface which can utilize a number of different database backends, including MySQL. While it has a lot to offer, Drupal has been criticized for being difficult to install and too complex for beginners. Fortunately, there are steps that can be taken to mitigate some of the confusing aspects of a Drupal deployment.

Drupal can be encapsulated in a Docker container very easily. Docker is a lightweight container system that keeps applications isolated and segregated. Its design makes it easy to distribute and deploy ready-to-go software packages, eliminating much of the effort and pain of installing and configuring large or confusing packages.

In this tutorial, we will deploy Drupal and MySQL on a CenturyLink Cloud Computer virtual server using Docker containers.

Tools Used

CenturyLink Cloud Compute servers are high-performance cloud servers. These enterprise-grade virtual machines are easy to deploy and manage from the CenturyLink Cloud Console and via our powerful API.

Before We Start

If you don’t have a CenturyLink Cloud account yet, head over to our website and activate an account. You’ll need it to access CenturyLink Cloud products.

Deploy a New Virtual Server with Docker

Our first step is to deploy a new CenturyLink Cloud virtual server. Follow the steps below.

  1. Log into the CenturyLink Cloud Control Portal.
  2. From the Navigation Menu, click Infrastructure > Servers. wl-drupal-docker-2.png
  3. On the left-hand side of the server panel, click on the server region.
  4. Click create > server.
  5. Fill out the form for your new server.
  6. From the operating system drop-down, select Ubuntu 16 | 64-bit.
  7. Click create server.
  8. Your request for a server is queued for provisioning. You can watch the progress of the request on the screen. Your server is provisioned when the status of all tasks in the queue is complete. wl-drupal-docker-3.png
  9. After your new server is provisioned, from the Navigation Menu in the Control Portal, click Infrastructure > Servers.
  10. Navigate to your new server and click on its name.
  11. Click more > add public ip.
  12. Check the boxes to open ports HTTP (8080) and SSH/SFTP (22). wl-drupal-docker-4.png
  13. Click add public ip address.

Installing Docker

The steps below guide you through installing Docker on your new virtual server.

  1. Log into the CenturyLink Cloud Control Portal.
  2. From the Navigation Menu, click Infrastructure > Servers.
  3. Navigate to the virtual server you provisioned and click on its name.
  4. On the right hand side of the server status page, look for IP ADDRESS(ES). Your server’s public IP address is underlined.
  5. From a shell or terminal on your local machine, connect to your new server with the following command. Observação: Replace "YOUR.VPS.IP" with your server's public IP address.

    ssh root@YOUR.VPS.IP
  6. Once you are logged into your virtual server, install Docker using the following commands.
    apt update
    apt upgrade -y
    apt install apt-transport-https ca-certificates -y
    apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  7. Edit /etc/apt/sources.list.d/docker.list to look like the following.
    deb https://apt.dockerproject.org/repo ubuntu-xenial main
  8. Install the required packages with the following commands.
    apt update
    apt install linux-image-extra-$(uname -r) apparmor docker-engine -y

Observação: You can also deploy a new virtual server with Docker through our Docker Engine Runner script.

Deploying MySQL with Docker

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. Siga estas etapas.

  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
  2. Go to http://YOUR.VPS.IP:8080/ in your web browser. Replace "YOUR.VPS.IP" with the IP address of your virtual server.
  3. Follow the on-screen instructions to configure Drupal. wl-drupal-docker-5.png
  4. When you reach Set up database, click ADVANCED OPTIONS.
  5. In the ADVANCED OPTIONS section, for Database name, enter "drupal".
  6. For Database username, enter "root".
  7. For Database host, enter the value of MYSQL-NAME for your MySQL container.
  8. For Database password, enter the value of MYSQL-PASSWORD for your MySQL container.
  9. Continue with the Drupal setup.

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.

Docker offers many options to deploy and manage software on CenturyLink Cloud Compute servers. Check out our other articles about Docker for more ideas and inspiration.

Sign-up for our Developer-focused newsletter CODE. Designed hands-on by developers, for developers. Keep up to date on topics of interest: tutorials, tips and tricks, and community building events.

We’re a different kind of cloud provider – let us show you why.