5 easy steps to a local development environment for WordPress with Docker

Dennis Andersson – May 24, 2021

1. Install Docker

Docker is an open platform for developing, delivering and running applications in so-called “containers”. With Docker installed on your computer, you do not need to set up a Virtual Server to run WordPress everything is handled by Docker.

To install Docker on your computer go to this link: https://docs.docker.com/get-docker/ download your package and follow the instructions.

2. Install Visual Studio Code or similar text editor

Visual Studio Code is an open source software development environment developed by Microsoft for Windows, Linux and Mac OS. The program supports several programming languages ​​and Git.

Download and install Visual Studio Code here: https://code.visualstudio.com/

3. Create a docker-compose file in a new folder

Docker compose is a tool for defining and running Docker applications with multiple containers. With Compose, you use a YAML file to configure the application’s services. Docker compose needs to be used because WordPress requires both PHP and mysql (database) to work.

Open Visual Studio Code and create or open a folder on your computer where you want the website files to be located.

Create a new file named “docker-compose.yml”

There is a good example of the contents of the file here: https://gist.github.com/bradtraversy/faa8de544c62eef3f31de406982f1d42

It includes WordPress, mysql and phpMyAdmin for easy access to the database.

Paste the contents of the file and save.

4. Launch your new WordPress website

To start WordPress, Mysql and phpMyAdmin, in Visual Studio Code click in the menu on “Terminal -> New Terminal”

In the terminal window that just appeared, type:

docker compose up -d

And press enter

Now the containers start up and you can see that you get more files in your folder.

After a while, you can go to http: // localhost: 8000 in your browser

Voila! Now your website is up and running and you can proceed with the WordPress installation.

To access phpMyAdmin go to http: // localhost: 8080 username and password for the database server can be found in the file docker-compose.yml

To turn off the services again, type again in the terminal:

docker compose down 

And press enter

If you start the website again with:

docker compose up -d 

Should everything you have done on the website remain.

5. Copy your website to your local environment or vice versa when you have completed the development

There are several good WordPress plugins to easily copy your website to other environments but I can recommend “All-in-One WP Migration” from ServMask.

You need to install the plugin both where you want to copy from and where you are going to copy as the plugin handles both export and import.

When you export from your website, it is important to keep in mind that URLs in the database need to be changed. Therefore, you add that you want to replace all text that matches your current domain with the domain you will then run.

If your current domain is https://www.example.com

You enter https://www.example.com to be replaced with http: // localhost: 8000

Do the export and download the file.

Then go to your local environment plugin and import the file. When it is ready, your website should be local and you can test and further develop without it affecting your production site. When you are done and if you want to get your local website to your production site, just do the opposite.

Do you want to know more?

Similar articles