thomas-shirley.com

Get going quick, with Docker

I confess. I had never used Docker prior to writing this guide. I would always boot a new VM instance and manually install the binaries I needed to fulfil my web development work.

apt-get install php-fpm
apt install nginx

...etc

After becoming tired of doing this dance each time I had to deploy a new application, I decided to give Docker a try.

This is a short guide about what Docker is, what it does and the things I was unsure about when I first started.

What is Docker

Docker is software that creates standalone, isolated instances of other software running locally on your machine.

It creates an isolated filesystem and a virtual system environnement, which can be interacted with directly from the host machine.

It allows you to very easily segment different versions of the same software on the same machine, without them interfering with each other.

With Docker, you can also destroy a container and all it's dependencies in one go. You don't have to manually unpick what you need and don't need when you change binaries.

How does Docker do it?

Docker has something called Containers, which are run from Docker Images.

A Docker container starts a predefined version of a particular binary, in an isolated namespace on your machine. E.g, an Nginx binary. You can run as many containers as you like - you can run 6 x Nginx containers on the same machine if you wish.

Docker works by running what can be viewed as cut-price Virtual Machines - with much less overhead. Docker doesn't actually create a virtual machine as it doesn't emulate any hardware.

Why do I need Docker?

A consistent environment, everywhere. To ensure the same environment in Production as Development, we run the same Docker containers in both. Because the binaries you choose to run are specified in advance and independent of the host machine, there's less juggling of versions and inconsistencies.

To share development environments is trivial (if you're onboarding a new developer), just share your Docker image.

My Questions

How do you run multiple instances of software inside the same container

You don't. Each Docker image should run one process and one process only. You run a container for Nginx, another for PHP and another for Postgres.

How do you create these Containers

You write something called 'Docker Files', which specify which binaries to pull in from Docker Hub and how they should execute.

I work for a massive company and have to pay :(

Swap to Podman - Red Hat's open source alternative that borrows many concepts from Docker. It can use Docker images too.

I bumped into this problem when I was thinking about using Docker at work - I couldn't accept the Terms & Conditions as I would need a subscription model.

Thomas - 29-12-2022