A Docker container is a piece of software that provides a particular application or service in a lightweight… container. Containers are often compared to virtual machines, and they are both heavily used in cloud deployments. But they are different.
- Virtual machines run on the host system’s hypervisor, which runs on the host machine’s operating system. A virtual machine contains a complete operating system and a kernel.
- Containers contain only enough code to run that application or service. It leverages the operating system of the host system for everything else it needs. In the case of Docker, containers run on Docker Engine (also known as the Docker daemon), a platform that sits on top of the host operating system and also coordinates communications for each individual container.
This difference means that containers are much smaller and more modular than virtual machines. While containers do rely on the host operating system, they are isolated from the host and from one another. The concept of isolation is important for security, but also means containers are easily transferred between environments and will function uniformly because wherever they are deployed, they will be running on Docker Engine. This standardization simplifies the development, testing, and deployment of containerized apps and services.
Although I do have workplace experience with containers, I am self-taught. I’m not a developer; I don’t have many applications where I actually apply what I learn. My one outlet is WordPress. While overhauling this website and updating some of the other tech-writing samples, I did some Googling to see if there was a way to use a container to create a local version of my WordPress site for development purposes. It turns out I can use three containers.
The five articles that this tutorial consists of are designed to be read and completed in sequence, but they do not have to be:
- WordPress and Docker: Introduction to Docker and basic Docker commands – Get started using Docker on the command line.
- WordPress and Docker: Use Docker Compose – Create your own Docker application that uses three containers to create a WordPress site that you can deploy wherever you can run Docker and Docker Compose.
- WordPress and Docker: Customize a Docker container – Open up some containers and work on them. Then save your work.
- WordPress and Docker: Build custom images with Dockerfiles – Build containers with an automated workflow defined in a text file so the container is created with what you want inside. No need to open it.
- WordPress and Docker: Putting it all together – Making some final changes to a Docker Compose file to deploy the entire application with a single command.
Prerequisites
This tutorial requires you to have some familiarity with and knowledge of the Linux command line, including text editors like Vi/Vim or Nano. I created this tutorial using:
- A MacBook Pro (macOS 10.14)
- The macOS Terminal with Zsh.
- A text editor. I like Visual Studio Code.
- Docker Desktop for Mac. Docker Community Edition, the free version of Docker, is available for Windows and Linux and can also be run on AWS or Azure. Find Docker CE for your platform.
- I also created a GitHub repo, wordpress_with_docker where I have shared the Dockerfile, YAML, and PHP files that I use in this tutorial. I recommend following the links I use and copying and pasting all of the text from each sample into your text editor. If you are more familiar with Git and GitHub, you can download or clone the repo.