Skip to content
Docker

How to setup a Drupal local environment with Docker and DDEV

In this post I will show you how to set up a Drupal local environment using Docker and DDev.

First of all we need to download Docker from their website.

Also you can use Homebrew:

brew install homebrew/cask/docker

Docker will provide the basic containers that Drupal needs to work. Instead of installing MySQL (for example) in our machine, the MySQL will be provided by Docker so we won't need to setup any extra tool in our local machine. Also, with Docker we will automatise all the process.

After setting up Docker Desktop it's time to install DDev. DDev is a helper for setting up a Docker project, instead of do the setup manually, DDev will configure all the containers needed for Drupal to work. Let's install DDev:

brew install drud/ddev/ddev

Once DDev is installed, be sure Docker is running in order to setup our new Drupal Project.

First we create our new project folder

mkdir my-drupal9-site

cd my-drupal9-site

Second we setup the config to tell DDev that our project will be a Drupal 9 project with docroot as base site placement.

ddev config --project-type=drupal9 --docroot=web --create-docroot

Now we can start the project (all the containers will be up)

ddev start

After the containers are up let's require via composer the latest Drupal version

ddev composer create "drupal/recommended-project"

Also we will require Drush

ddev composer require drush/drush

Now let's proceed to install automatically

ddev drush site:install -y

And also get an Admin user

ddev drush uli

Finally we can launch the project

ddev launch

After all this process we will be able to access to a brand new Drupal local environment using Docker and DDev. Now we can start develop our project.

Don't forget to export configuration with drush cex and also create backup from your DB ddev export-db, since you can lose all your data and changes if you destroy the Docker containers.

© 2021 Cataco