DEV Community

Mel Wang
Mel Wang

Posted on

Docker Part 1: Installation and Hello World

This is a post for myself to take notes on Udemy's course "Complete Docker and Kubernetes Course - learn all core Docker features including Dockerfiles and Docker Compose"

Table of Contents

  1. Download Docker
  2. Run hello-world image in Docker
  3. Run ubuntu image in Docker

Download Docker

  1. I have a mac, so I installed it from this link: https://docs.docker.com/desktop/setup/install/mac-install/
  2. A docker.dmg file is downloaded. After it's done downloading, double click it and move it in the Applications folder.
  3. Run: docker --help. If it shows the following then you installed docker successfully.

output

Note: if it returns:
zsh: command not found: docker
then it may not be pointed correctly in the path. Run:
echo $PATH to see if docker is present. If not, run:
export PATH="/Applications/Docker.app/Contents/Resources/bin:$PATH" and try docker --help again.

Run hello-world image in Docker

When learning a new programming language, people often start with a Hello World program. In Docker, we do something similar using the hello-world container.

Running this container helps verify that Docker is installed correctly and introduces the basic components of Docker.

Step 1: The Command

We start with the following command in the terminal:

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

hello-world
So what happened here?

Step 2: Actors

Before we walk through the steps, it helps to understand the actors involved in the process.

1. Docker Client (CLI)

The Docker client is the program you interact with in the terminal.

Example:

docker run
docker ps
docker build
Enter fullscreen mode Exit fullscreen mode

The client’s job is to:

  • receive commands from the user
  • send requests to the Docker daemon
  • display the results back to the terminal

Think of it like a remote control for Docker.

2. Docker Daemon (Docker Engine)

The Docker daemon is the background service that does the real work. It:

  • downloads images
  • builds containers
  • starts containers
  • manages networks and storage

The daemon is always running in the background once Docker is installed.

3. Docker Registry (Docker Hub)

Docker images are stored in a registry. The default public registry is Docker Hub. Docker Hub contains thousands of images such as:

  • nginx
  • redis
  • postgres
  • hello-world

If Docker can't find an image locally, it will download it from Docker Hub.

4. Docker Image

An image is a template used to create containers. You can think of it as a blueprint for an application. Images are read-only and contain:

  • application code
  • runtime
  • dependencies

5. Docker Container

A container is a running instance of an image.

Relationship:

  • Image → Blueprint
  • Container → Running program

Multiple containers can be created from the same image.

image

Step 3 — What Happens When You Run the Command

  1. You type the command in the terminal. docker run hello-world.
  2. The Docker client sends this request to the Docker daemon.
  3. The Docker daemon checks whether the hello-world image already exists on your computer.
  4. If the image exists locally, it'll use local image. If not, the daemon will pull image from Docker Hub.
  5. The Docker daemon pulls (downloads) the image from Docker Hub. Once downloaded, the image is stored locally. You might see output like:

Pulling from library/hello-world
Digest: sha256:...
Status: Downloaded newer image

  1. After the image is available locally, Docker creates a new container from that image. Think of it like:

Image = blueprint
Container = running machine

  1. The hello-world container runs a very small program. Its only job is to print the following message:

Hello from Docker!
This message shows that your installation appears to be working correctly.

Once the message is printed, the container finishes execution.

  1. The container exits automatically. You can confirm there are no running containers with:
docker ps
Enter fullscreen mode Exit fullscreen mode

Output will be empty.

Run ubuntu image in Docker

Step 1: The Command

Run the command in the terminal:

docker run ubuntu
Enter fullscreen mode Exit fullscreen mode

Notice that nothing is done and the container is stopped after running /bin/bash. Why?
ubuntu
This is because there was no command that was executed inside of this ubuntu container. We can check that the ubuntu container is exited by running either of the following to see docker container run history (both yields the same results):

docker ps -a
docker container ls -a
Enter fullscreen mode Exit fullscreen mode

Then how do we start ubuntu and let it keep running? The following command does the trick:

docker run -it ubuntu       // "i" - interactive mode (user can key in input)
                            // "t" - pseudo-TTY (terminal)
Enter fullscreen mode Exit fullscreen mode

Now you're inside the ubuntu container! You can treat it as a Linux shell and can run any Linux command.
run ubuntu
To exit the ubuntu container, run exit. As soon as you exit, the process bash of ubuntu gets terminated, and the container will stop running.

Additional Information:

  • busybox is smallest Linux image with minimal Linux utilities
  • alpine is based on top of busybox

Top comments (0)