What is Docker?

What is Docker?

The Meat

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the requirements, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can be assured that the application will run on any other machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

Docker (and container system in general) are commonly confused with virtual machines. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application. You can learn more about containers here.

Because all the work is done to prepare the project within the container on it’s extremely useful in development as well as production to spinning up disposable services a single line such as

docker run -p '5432: 5432' -e POSTGRES_PASSWORD=mysecretpassword -d postgres

will setup a running postgres server ready to accept connections, this can be done with most tools and apps like mysql, wordpress, and drupal.

The Potatoes

Containers are just scratching the surface of docker, it also supports docker volumes which isolates data and docker network which allow containers to run on entirely isolated and private networks, with set ports between them adding an extra layer of protection.

Docker Compose

Docker Compose is by far my most loved feature of docker, it allows me to create an entire development or live environment with all the moving parts, all private networks and volumes (mounting local files for testing) by using a single config file: docker-compose.yml. This can mirror or even be used in production,  removing the “it works on my environment” argument from the equation.

Here’s an example docker-compose.yml to spin up a simple wordpress

version: '3.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:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    volumes:
      db_data: