I have been using with Docker for a while now. Mostly for running isolated Docker WordPress and Docker Magento 2 development environment. With it’s docker-compose you can really automate/optimize the process of creating a new isolated development environment for a new project. If we take for example WordPress, we need 3 containers:
The last one is optional. If you are using Mysql Workbench, you don’t need to include it.
Setting up Docker WordPress development environsment
Let’s say you are new to docker-compose. The first thing you neeed to do is to create a new folder
mkdir test cd test
Inside this folder create a new file docker-compose.yml
version: '3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "80:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress phpmyadmin: image: phpmyadmin/phpmyadmin:latest ports: - 8181:80 environment: MYSQL_USERNAME: wordpress MYSQL_ROOT_PASSWORD: wordpress PMA_HOST: db volumes: db_data:
In this file we define all of the three containers (mysql, wordpress and phpmyadmin). To bring those containers (a.k.a Docker WordPress development environment) to life, just type the following command:
docker-compose up -d
The images will be downloaded and the containers will be started.
If you are not the shell guy, I suggest you to install Kitematic, which is a GUI for docker. It will enable you also to change some parameters, but I prefer to do it in the above file docker-compose.yml I am using mostly to retrieve the virtual container IP and so to access the WordPress site (Example on the image below).
For example: My WordPress site is now accessible on the URL address: http://192.168.99.100 (port 80)
OK, now the Docker WordPress development environment is up and running. The next question is, how to access the Docker WordPress files. The easier way to managed it is through Kitematic.
Just click on the volume /var/www/html (visible on the image below), which will be instantly mounted and files will be displayed in the selected folder (which will also be automatically displayed).
The described process above is covering everything you need to know About Docker for a simple Docker WordPress development. But if you want to dig dipper into doker, checkout my blog post Docker Cheat Sheet.