Docker is great tool for containerizing services and applications. Although it's commonly used to deliver micro services, you can also use it in your monolithic applications.

Dockerizing an Application

With Docker you can transform your application's production and development environments into one more more containers working together.

  • Docker Image - A Docker image is built from a set of instructions provided in a Docker file such as what image to use as the starting point and what software to install.
  • Docker Container - A Docker container is a virtualized operating system that is initialized from a Docker image.
  • Docker Compose - This utility allows you to build and launch multiple containers at once.

How I Use Docker

One of the most important features of Docker is being able to set up an entire server using a single file called a Docker file. I use Docker Compose which allows me to configure multiple containers from a YAML file and deploy them with a single command. This is useful as a developer because all I need to set up a local development environment is to have Docker installed whether I'm on Windows, Mac, or Linux. In production, Docker allows me to quicklyg rebuild images and replace containers when updates are needed. I don't have to worry about forgetting what software I installed or what environment variables I set to get the server running because everything is in a Github repo.

For web applications I have four separate containers: Caddy, Workspace, PHP-FPM, and MySQL. I use Caddy because it's similar to Nginx but is much easier to get HTTPS working for websites in production. The Workspace container is mainly for development. PHP-FPM processes all incoming HTTP requests that require PHP. Each container has it's own error logging that I use for troubleshooting when there's a problem with one of them.

When I want to deploy an application I set up an AWS EC2 instance and install Docker and Docker Compose. From there I just have to run docker-compose up -d to run each Docker container in the background. Using Docker Compose I am also able to SSH into any container when I need to.