Getting started with Docker

Installing the Docker engine and running your first container

Patrick Farrell
4 min readFeb 12, 2019
Photo by chuttersnap on Unsplash

In my last article about Docker, I introduced you to a few core concepts: images, containers, and Docker files. I want to start diving in a bit deeper here about how to actually get started running your first Docker container.

So if you remember from the previous article, a container is launched by running a Docker image, and a Docker image is built by creating a Docker file that describes the image. But there is one pretty important concept that I left out. There is one core dependency that must be installed on the host operating system for all of this to work, the Docker engine itself.

Install the Docker Engine

The Docker engine is a system that runs on top of the host operating system. Docker has been designed to run on Linux, Windows and Mac OSX. While you must install a Docker Engine designed for each OS individually, the nice thing is that the images themselves are cross platform. So if you build an image on a Linux machine, it should run on an OSX machine that has the Docker engine also installed.

Rather than write out all of the instructions for installing Docker, I think it is best that I just point you to the official installation documentation here. The most important thing to note is that you typically just want to install the Docker Community Edition (CE). There is also an Enterprise Edition (EE), but when you are just starting out, this is unnecessary for your needs.

After the installation process is complete, you should be able to open a Terminal application and type “docker” to prove that it has been installed properly.

Pulling and running your first Docker container

As you continue to follow through the official Docker getting started guide, after installation it will instruct you to test out your Docker installation with a Hello World program.

We have talked a lot about these Docker images so far and how they are built from Docker files. But one of the most interesting things about Docker is that you can also run pre-built images from other developers. You don’t have to actually build the image yourself to successfully run the code on your newly installed Docker engine.

So for our next step we are going to run a Hello World program built by the Docker community. In a Terminal Window, run the following command

docker run hello-world

With this command, we are telling Docker to run a program called hello-world. I bet you may be asking at this point though, where did the hello-world image come from? Up to this point, I have not instructed you to download any images from the internet.

Well this is another cool feature about Docker is that it first searches our local machine for the image we wish to run, and if the image is not present, it reaches out to the main Docker Hub registry on the internet to pull the image down before it runs it locally.

You can think of the Docker Hub registry as a centralized repository of a bunch of pre-built, ready to use Docker images. You can download other developer’s images to run on your machine, and you even push up your own Docker images to Docker Hub so other developers can run your code.

After you run this hello-world image, the resulting output should look like this.

Hello from Docker!

This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the “hello-world” image from the Docker Hub.(amd64)

3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.

To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/

For more examples and ideas, visit:

https://docs.docker.com/get-started/

What happened here was that we pulled down the hello-world image from the Docker Hub registry, it ran the image as a container and output the result above, then the container closed. If we tried to run hello-world again, Docker would skip the download step because the image is present on our local host machine.

I encourage you at this point to follow through the full Docker getting started guide. You will gain valuable insights into using Docker with more detail than I have provided in this article. In our next Docker article, I will begin to explain how to build your own Docker image rather than pulling it down from the Docker Hub registry.

If you have any questions or comments about this process of getting started with Docker and running your first container, please let me know in the comments below.

--

--

Patrick Farrell
Patrick Farrell

Written by Patrick Farrell

Founder and Business Coach for Online Entrepreneurs and Coaches. I help people create more freedom in their life and connect to their purpose.

No responses yet