First Dip into Docker

Jack Paczos
Get that Data!
Published in
4 min readJan 24, 2024

This post shows how to get started with docker.

Docker Image

Docker is an amazing tool, which is often overlooked by developers since it seems unnecessary and scary.

In essence Docker is a way to share your applications, so that everybody can run them.

I will first talk about what problem docker solves and then proceed and introduce a few of the very basic concepts.

Problem:

Imagine you have created this cool app and you proudly want to share it with other developers and friends. However when they use your code it will most likely not work. Since they will have some programming languages or dependencies not installed or have different versions of them. Now, they could install and configure everything like you did. But how much time and effort would it cost. Especially with big applications it would truly be a pain in the ass.

Solution:

Docker is this magical tool which solves this problem. You can wrap your app inside a so called Container which will include all the correct versions of programming languages, commands, dependencies and so on. Others can now copy this container (which is isolated from your local setup) and run the application inside it. The application will work in the environment it was designed to and nobody will have issues with versioning.

Docker is also useful for many other things like database containers, CI/CD or for creating proxies.

So let’s get our hands dirty as to not be afraid of the mysterious docker.

Content:

  1. installing docker
  2. core concepts
  3. getting image
  4. run container
  5. checking processes

1. Installing Docker (macOS)

Just navigate to dockers website and install it like any other app on macOS.

Upon installation put it inside the applications and open it.

It should look somewhat like this:

Before we do anything more. You need to understand 2 core elements of docker.

2. Core Concepts

Images:

an image is like a blueprint to create containers. Think classes and objects. The image defines languages, dependencies and their versions which the container will inherit.

Containers:

are instances of an image. With one image i can make many containers. Containers can be running or not. They are the wrapper in which applications or services are wrapped

Docker Daemon:

is a background process which manages everything with containers and images. It creates, runs and coordinates all. If the daemon is not running, you can’t create or delete containers and images.

3. Getting Image

You can either create your own Image or you can pull an existing one. There is a website with existing Docker Images it’s called Docker Hub. It works like PyPi or Github you can select an Image you like and pull it.

Before pulling ensure that the daemon is running. When you open the Docker Desktop app you can see in the bottom left corner if it is running or not.

You can also check via terminal

docker info

If the daemon is not running, a messages like this will be returned.

Server:
ERROR: Cannot connect to the Docker daemon at unix:///Users/jacek/.docker/run/docker.sock. Is the docker daemon running?
errors pretty printing info

If you don’t have an error it means the daemon is running.
Now you can pull whatever image you like from docker hub.

Hello World is a minimal example image; you can check it out here.

docker pull hello-world

You can open docker desktop and you will see the hello-world image at the bottom on the images page.

4. Running Containers

Since we have now an image. We can create a container. This we can do either in Docker Desktop by clicking on the run button or via the command line by typing:

docker run hello-world

This should output a message from docker

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.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to 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/

5. Checking Processes

Very often you will need to check if a container is running. This can be done by checking the processes.

docker ps

Will return the currently running processes (process status)

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

You might wonder why it is empty.
This is because currently no container is running. The container which returned the hello from docker message is not running anymore.

When you run

docker ps -a

You will see both running and stopped containers.

CONTAINER ID   IMAGE              COMMAND                  CREATED             STATUS                      PORTS     NAMES
c1cc9eba9b0e hello-world "/hello" 8 minutes ago Exited (0) 5 minutes ago flamboyant_cohen

Congrats! Now you can got a first feel of docker.

--

--