I have been playing around with Docker recently and came to a conclusion why I would stick with Docker for my local development instead of using Vagrant. I have been using vagrant for couple of years now and It has been very very good to me because I can create multiple site instantly with little script and automatically creates a database, WordPress and login information to WordPress but decided to give Docker a try and here is my experience with it.
When I first started using Docker few months back, it was Docker for Windows, Dock for MacOS and of course Docker for Linux Distributions. When I first started, using Docker in Windows, I had to upgrade my Windows system to Windows 10 Professional because Docker for Windows by default uses Hyper-V. Having to experience Linux under Hyper-V isn’t my greatest choice, personally, I don’t like Hyper-V because of how the interface is and how is setup and after a long time of use, I just didn’t seem to like it. I think maybe because I have been using VirtualBox and VMware so long that, I got used to the fact that they’re kind of better than Hyper-V, but my personal opinion.
Then went on testing Docker in MacOS, seems pretty straightforward, even if MacOS has own virtualization built in, I believe it is called MMU Virtualization to be able to run Docker, you eventually need at least a OS X El Capitan 10.11 or higher for better performance and support, anything like 10.10.3 (Yosemite) may work but has limitations. I don’t want to get into more detail but like to discuss about Docker Toolbox instead since that’s the main thing about this post.
But first, Using Docker in Linux is 100% awesome because docker is install natively and doesn’t need virtualization so when you create a config with with static IPs, everything works flawlessly and usually don’t need to worried about setting up hostnames with the static IPs.
Using Docker Toolbox
Why Toolbox because it uses VirtualBox, the reason why I went this route because then I can install other operating systems with no problems and not having to worried about Hyper-V if it supports Windows XP or Windows 7 or any other operating system especially Linux Distributions. Even if Hyper-V works well with Linux Distributions, to me the experience of creating and doing stuff on it isn’t as smooth as I would like it to be.
My Setup for Docker Tool
Windows 10 Professional and Windows 10 Home will work perfectly fine, but do remember if you want to use Docker Toolbox and running Windows 10 Professional, you will need to uninstall Hyper-V because you will not be able to use both at the same time. Once you have uninstall Hyper-V, install the latest VirtualBox with its Extension Pack. After you have successfully install VirtualBox, next you will need to download and install Docker Toolbox and make sure that VirtualBox and Git is installed.
Once you have finished installing Docker Toolbox, click on Docker Quickstart Terminal, you will be using this to create, modify delete and other cool stuff that comes with Docker. During that time, it will create a new VM and it will configure whatever it needs to run, after it finished, you will see an IP address of
192.168.99.100 but you won’t able to access it yet since we haven’t setup an apache server but first we need to add a new shared directory under directory so that our WordPress files can be access locally on your computer without the need to setup stupid permissions. Please then head over the Terminal that you were using and type as follow:
docker-machine stop, this will power off the virtual machine.
Open up VirtualBox Graphic User Interface, click and highlight default since that’s the Docker Virtual Machine named by default, click on Settings on the top and head over to Shared Folders and click Add Share with the green plus with a baby blue folder, since by default when you use the Docker Quickstart Terminal, you will be at
C:\Users\. Please note that you will see a shared folder already that is targeting the
C:\Users, by default docker uses this for default shared, but I like to keep my stuff organized so I will use the following path
C:\Users\ and the folder name should be
sandbox, as you can see below.
The next step is to power back on the virtual machine by typing:
docker-machine start, this will power on the virtual machine and you can see that it will boot and it will assign an IP address, the IP address is usually
192.168.99.100, if not then you can check by typing:
docker-machine ip. After the docker virtual machine is up and running, we will need to permanently add path inside of the virtual machine so that we can permanent access without the need to redo this part if the virtual machine is power off.
If your screen is full of commands from last time, I would recommend clearing the screen and type the following to ssh into the virtual machine:
docker-machine ssh, this will login into the server itself and we will need to add the following lines of command. After logging in, type the following to edit file:
sudo vi /mnt/sda1/var/lib/boot2docker/profile, you can only use vi since that’s the only thing that you can use, scroll down and insert the following lines:
mkdir -p /mnt/storage/sandbox mount -t vboxsf -o defaults, uid=`id -u docker`,gid=`id -g docker` sandbox /mnt/storage/sandbox
Please note note that to save the file, make sure to press
:wq to write and quite. If you need to write, I usually press
a to insert stuff. After you have save that information, type
exit and restart the virtual machine to make sure that it takes affect by:
docker-machine restart default.
After virtual machine is up and running again, head over to the sandbox folder you create earlier at
C:\Users\ and create a file called docker-compose.yml and copy this to the file.
version: '2' services: sandbox: image: wordpress:php7.1-apache container_name: sandbox_wordpress ports: - '80:80' environment: WORDPRESS_DB_NAME: sandbox WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_TABLE_PREFIX: wp_sandbox_ volumes: - './public_html:/var/www/html' networks: mynet: ipv4_address: 172.26.0.5 mysql: image: mariadb container_name: sandbox_mysql environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: sandbox MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress volumes: - db_data:/var/lib/mysql networks: mynet: ipv4_address: 172.26.0.6 aliases: - mysql phpmyadmin: image: phpmyadmin/phpmyadmin container_name: sandbox_phpmyadmin environment: - PMA_ARBITRARY=1 ports: - '2087:80' volumes: - /sessions networks: mynet: ipv4_address: 172.26.0.7 volumes: db_data: networks: mynet: driver: bridge ipam: config: - subnet: 172.26.0.0/24
After you done that, save the file and head over to the terimal where the sandbox is at and with one file called docker-compose.yml, the next step is to type the following to download WordPress, Mariadb and phpMyAdmin:
docker-compose up -d, when it finished, you should be able to check to see if the following services are up and running by typing:
docker ps, then head over to the IP address:
192.168.99.100, WordPress should now be started and you will see a new folder called public_html which contains all WordPress files. phpMyAdmin should be at
One thing I like to do is to use host names instead of IP address, this you will need to have administrator privileges to able to edit the hosts file in Windows 10. That’s all.
I was just curious about how the shared directory works so I took another computer did exactly the same thing and decide not to add the additional shared directory as I mentioned. It seems like the
C:/Users is pretty much shared so the step to adding a shared directory again inside of
C:/Users, this means that inside of sandbox, when you compose up, it will just create the public_html automatically because the entire
C:/Users is shared. Well good to know.
I personally think that, the way I did it makes sense too because if you were to use
C:/Users as default, you would have to go deep into the location to find the WordPress Files whereas, by doing what I did, its just the
/mnt/storage/sandbox location, so less
cd to use, but I think if you have projects that are outside of
C:/Users, then theses steps will do you do good for sure.