WordPress Local Development With Docker – Installation Guide
[Cover Image from johnny.chadda.se]
I wrote this post to let newbie on Docker can do it in likely step-by-step to deploy WordPress on local machine for development purpose. You should understand about what Docker is, if not, then go to read document here.
This is a simple guideline for Linux based machine.
First, you have to pull the image of MySQL. This is because of WordPress official image doesn’t included the RDBMS in itself.
$ docker pull mariadb
Above command will download the mariadb (MySQL forked) to your machine. Next, you just run the MariaDB image.
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=somepassword -d mariadb
With above command, Docker will initiate Image from -d mariadb then set a mysql root password. This container will be named mariadb ( –name mariadb )
Next, what you need is WordPress image.
docker pull wordpress
Now, almost the last step, you just want to link the WordPress container with MariaDB.
docker run -p 8081:80 -v /var/www/wordpress:/var/www/html --name wordpress --link mariadb:mysql -d wordpress
This command will create another container with WordPress image, then with -p 8081:80 it will mapped network port on your machine (8081) to WordPress container at port 80, then later you will be access the WordPress look like you installed in your local machine. (http://localhost:8081), without this parameter, you will need to know the IP address of WordPress container and then access that IP instead (http://<wordpress_container_ip_address)
The option -v /var/www/wordpress:/var/www/html will let you make local development easier as you can edit directly in /var/www/wordpress directory. This is shared folder, when you updated any file in /var/www/wordpress then the container at /var/www/html will update as well. (/var/www/html is a directory of WordPress in the WordPress official image)
The option –link mariadb:mysql will link service in difference container. In this case, we would like to let WordPress container use MariaDB container for database component.
Now, we are done setup container for the WordPress. Access http://localhost:8081 to enjoy WordPress.