A quick rundown guide without the lingo and frills
Docker. It’s a little blue whale with a container sitting on its back. We hear about it from various places but it’s usually just left to the DevOps guy to deal with.
Or perhaps you’ve tried to pick it up out of curiosity. So you start with Google and the amount of information returned just feels overwhelming. In this piece, we’re going to go over what Docker is, how it works, and the differences between a Docker container and a virtual machine.
What is Docker?
Docker is a development platform and a virtualization technology that makes it easy for us to develop and deploy apps inside neatly packaged virtual containerized environments.
What does all this mean?
There are two parts to Docker — the Docker image and the Docker container.
The Docker image is the file used to execute code in a Docker container. A Docker container is the virtualized runtime environment. You can think of a container as the thing that runs the image.
This means that apps run the same, no matter where they are or what machine they’re running on. A docker container — or the virtualized runtime environment — creates a little ring-fenced sandbox that makes sure that the environment and settings are the same everywhere.
Perks of Docker:
- can be deployed to any machine without any compatibility issues
- the software stays system agnostic and less work to develop (because you’re not supporting every possible setting and configuration to make it work)
Other notes on Docker:
- Docker containers can run on your computer or server
- they act like little ‘micro computers’ — each with specific jobs (i.e. hosted application/software) and their own operating system, their own isolated CPU, processes, Memory, and Network resources.
- the ‘containerized’ system makes it easy to add, remove, start and stop without impacting other host machines.
- Docker containers often only run one specific thing, such as MySQL database, a nodejs application, python scripts, WordPress instance, or anything you want.
- Containers can be networked together so that each ‘micro machine’ can talk to one another.
What is DockerHub?
DockerHub is an online repository of Docker containers with pre-configured environments for a specific programming language or setup to get started. It’s like where all the boilerplates for systems configuration live.
That’s basically it. You can download any of these Docker images for free and configure them to run your apps the way you need them to. Once that’s done, you can ship your image to other machines and replicate your environment without the hassle of trying to make it work.
To pull a docker image from DockerHub, you can just use the
pull command. For example:
docker pull ubuntu
You can add tags to the end of your image pull to get a specific version. If no tags are present, you will get the latest version available.
Docker Container vs. Virtual Machine
Docker is a form of virtualization — but it isn’t a virtual machine.
In a virtual machine (VM), it has to quarantine off a set amount of resources, hard disk space, memory, and processing power. It needs to emulate hardware, and boot up an entire operating system.
Then the VM needs to communicate with the host computer via a translator application running on the Host Operating System called a “Hypervisor”.
Here’s a diagram:
In contrast, Docker communicates natively with the system kernel, bypassing the middleman on Linux machines, Windows 10, and Windows Server 2016 and above. It uses less disk space and you only need a single copy of files needed and share them between containers.
How to create a Docker container (the theory)
You start with a Dockerfile (yes, there are no spaces, this is not a typo), which can be built into a Docker image. You then run this image on your Docker container.
A Dockerfile is a simple text document that instructs how the Docker image will be built. It’s like the blueprint of all the things you need. Think of it like the
packages.json file equivalent — but Docker.
Things you’ll need for a Dockerfile are:
- your base image
RUNcommands for downloading, installing, and running your software/app. So here, you can add things like links to your GitHub repo, how to unpackage it etc.
Once your Dockerfile is complete, you can build it to form the Docker image. The command looks something like this:
docker build -t [dockerImageNameYouWantHere] [location of dockerfile here]
To check that everything went as planned, you can verify it with the following command:
Now your built image can run a container of that image or push it to the cloud to share with others.
To run a container, it’s just a simple
run command, followed by the image name.
docker run imageNameHere
Wrap up: where to from here?
I didn’t really go over how to set up Docker and how to use it. In part, it’s because it’s out of scope for this piece. I wanted to keep it as a simple introduction for complete newbies to get the general gist of what Docker is and how it works.
However, if you want to explore further, here are some helpful resources that can help you on your way to becoming a Docker pro.
- Setting up Docker: Get started with Docker Compose
- Writing your Dockerfile: Dockerfile reference
- Docker Tutorial For Beginners: How to Run Applications in Containers (YouTube)
And that’s basically it for this piece. I hope you’ve found it useful and thank you for reading. 😊