An Intro to Docker

Aug 10, 2021
Mandy Arola

A question we hear often from our Seekers is what should I work on during my job search. Many graduates will add features to their capstone projects or turn their front-end capstone into a full-stack capstone. Others are eager to dive into another language. Recently, Will Johns met with our Seekers to give them an introduction to Docker and share why he thinks graduates should spend some time learning it.

What Is Docker

At its core, Docker is an ecosystem consisting of small virtual machines and the tools and systems that are built around them. While Docker containers do have some differences from traditional virtual machines, most use cases fit this definition.

“Docker facilitates stand-alone application development, distribution, and deployment, and solves the ‘works on my machine’ problem,” explains Will. As long as your machine can run Docker, you should be able to run any Docker Image. It’s also highly portable and can be run on micro-computers like Raspberry Pi all the way to enterprise servers.

Fun fact: Docker is an eponym. In the same way Kleenex is eponymous for facial tissues, Docker is eponymous for containerization tools. There are other container solutions, but Docker is the most well known.

Why You Should Care About Docker

“Docker is like Git. You can get about 80% of the functionality you’ll ever need from Docker by knowing about 20% of the commands and it’s used almost everywhere.” - Will Johns

“Every company I have worked with in the past 6 years have used Docker in some capacity,” shares Will. Some companies use it only for deployment; while others only use it for local development. You’ll also find companies using it for a mix of both and everything in-between. While utilization and exposure to Docker may vary from company to company, there are new tools coming out for containers all the time and Will believes containers are here to stay.

Docker is also approachable for all levels of development, from juniors to architects, and used in a wide range of industries, from healthcare to gaming to data science. Need another reason to learn Docker? It can be used with every language -- JavaScript, C#, Python, R, etc.

“Because of its wide adoption and application, and because you can really dig into the depths of it and become very proficient with it, it’s a really good value add for your personal offerings for a company or hireability in general,” Will advises. And while you probably won’t work on writing Docker images when you start your first junior developer job, you’ll most likely be exposed to Docker and it’s tools pretty quickly.

Core Commands And Terminology

Before diving into how Docker works, it’s helpful to know the terminology. Will outlines the terminology as follows:

  1. You write Dockerfiles.
  2. You build Dockerfiles into Images.
  3. With a built Image, you can tag Images for identifiers/versions. (The tag is a unique label similar to commits in GitHub to identify that version of the build.)
  4. You can Push/Pull Images to a repository. (This is a bit different from GitHub, but you can share versions as artifacts.)
  5. You run Containers based on Images.
  6. You can map Ports to containers to facilitate network traffic, like API calls from your host machine.
  7. You can mount Volumes in Containers to share files from your machine to the Docker Container.
  8. You can connect Containers to Networks to enable them to talk to each other. (By default Docker Containers don’t know about other Docker Containers, but you can configure them to work together.)

Will continues to break these concepts down a bit more.

Dockerfiles

You write Dockerfiles. Dockerfiles are like a schematic or blueprint and there are plenty of templates and examples that you can use rather than creating one from scratch. While you can name them anything, they are typically named “Dockerfile.” 

Basic structure of a Dockerfile:

FROM - This gives the Dockerfile the starting point.

COPY - This moves a set of files from your host machine into the Docker Image.

CMD - This sets the default when someone runs the file normally - “This is what you’re going to do unless otherwise specified.”

Docker Images

You build Dockerfiles into Images. Images are similar to an executable or program. They are pre-packaged and ready to run with a list of instructions, source code, and usually some application built into it. The images are tagged with an identifier, with “latest” often used to notate the most recent version. But like naming the Dockerfile, you can use anything for the tag. Images can be pushed/pulled from a repository, like Dockerhub, a host service. You can also configure things like resource limits (RAM, CPU, or Disk), and Port Mapping at runtime.

Docker Containers

You run Containers based on Images. Will explains, “When you run a container, it is an instance of a given Image. You can have containers of multiple Images. You can [also] have multiple containers of the same Image [and] start up any number of versions or instances of your same application. This is a common practice for scaling applications during deployment. Each instance is isolated by default...it’s own stand alone machine.”

Ports, Volumes, and Networks

You can map Ports, mount Volumes, or connect Networks to each container. Will walks us through how this all works.

“By default you have your host PC running a Docker Container with one-way communication from Docker to the Host PC of terminal output (logs, print statements).”

Docker Container and Host

“You can expand on that with Port Mapping. [As an example,] my machine’s Port 8000 is the Container machine’s Port 8000, so that you can communicate with network traffic.”

Docker - Port Mapping

“You can then do a Volume Mount to share files. To get logs out or do real-time reloads if you want to use a container to do your local development and then persist file changes.”

Docker - Volume Mount

“A Shared Network connects containers so they can communicate with each other and ultimately your Host through the connections made with the first container.”

Docker - Shared Network

So now that you know the basics of Docker, it’s time to dive in and start learning. You can download Docker here and explore more resources here.


Will Johns is a Staff Software Engineer at Butterfly Network, Inc. and an avid NSS supporter. Python is his favorite language and while he spends most of his days working as a full-stack web developer, his free time revolves around the embedded electronics world.

Topics: Learning, Analytics + Data Science