How to start using Docker

By Rohit Ghumare 7 min read
How to start using Docker

In 2013, Docker revolutionized the virtualization space with Docker Engine. Containerization became more mainstream, and Docker became ubiquitous to containers. 

With Docker, developers could standardize the environments for their applications to work in. These standardizations made way for smoother deployments and faster time to market. 

In this blog, we tell you everything you need to get started with Docker. This is part of our extensive series of blogs on Containers

If you wish to refresh your memory on what Containers are, you can start here. Let’s start by understanding a Docker system and how it works. 

There are some important terminologies and concepts in Docker that you need to know before you can start to use Docker. Let’s go through them one by one.

Docker basic architecture

Internally, Docker uses a client-server architecture. Here is a simplified view of the docker architecture.

Source: Docker

Let us now go through each component of the architecture.

Docker server daemon : dockerd

Source: Docker

Docker daemon is the server in the architecture. Docker daemon does all the important tasks like building, running, and distributing Docker containers.

Dockerd daemon can listen for Docker API calls and requests. The daemon can even communicate with other daemons to manage more services. Docker daemon resides in what is called a host system (DOCKER_HOST).

Docker client: docker command

Source: Docker

docker” command is the client in Docker architecture. Most Docker users use this docker client to interact with the server, i.e., dockerd. The client uses Docker API to talk to the Docker server. 

The most common parameters to docker command are: build, pull and run. We cover these commands in the next section.

Docker image and container

Let us now understand the difference between a docker image and a container. 

Source: Docker

A docker image is a read-only file that contains all instructions necessary to create a Docker container. One image is often used as a template based on which other images are created.

The image will typically have many layers. Each layer will depend on the layer below it. The bottommost layer will have a base image defining the operating system, and each layer above will have other dependencies mentioned for the containerized application to run.

Source: Phoenixnap

Instruction files to create images are called Docker files. They are written in YAML. Public images are often stored in a public repository called Docker Registry

Docker file

Here’s a sample dockerfile that runs an echo command in a Ubuntu system and puts “Hello world” into a text file.

Source: GitHub

A container is a running instance of an image. This means that a container is defined by the image. The docker command or Docker APIs are used to create, manage and destroy a container. 

Each instruction in a dockerfile creates an image layer. When some instructions are changed, only the layers which have changed are rebuilt. This abstraction makes containers lightweight and fast.

We cover how to create and run your first container image in detail in this blog.

Containers, by default, run in isolated environments. But they can be controlled by writing instructions in the Dockerfile. You can change how a container’s networking is set up. It is possible to make different containers communicate with each other. We cover container networking in detail here.

Unless specifically mentioned, container data is not stored persistently. Container data is destroyed along with the container. If your application requires persistent storage, you can set it up in many ways by writing instructions in the docker files. We have written about handling container storage in detail here.

Docker registry

Source: Docker

Docker Registry is a place where Docker images are stored. These places can be public or private. Docker runs a public Docker Registry called Docker Hub. This is the largest repository of Docker images. 

By default, the docker command looks for images on Docker Hub. You can reconfigure it to look at any other Docker Registry as well.

Source: Docker Hub

Popular Docker commands

Let us now look at the most popular and most commonly used docker commands to start using Docker.

docker build

Docker build is the way to create docker images from docker files. Docker files contain instructions on how the docker image should be. The command requires a dockerfile and the place from which the necessary files need to be picked. 

A common way to use this command is to mention the repository URL where all the files are kept. For example, 

Source: Docker docs

This command will clone the GitHub repository mentioned and use the Dockerfile in the root of the repository to build the Docker image.

You can read more about the docker build command from the official docker documentation.

docker pull

docker pull command will download the mentioned Docker image from the Docker registry. As mentioned earlier, the default docker registry is Docker Hub. 

For example, the below command will download the docker image of the latest version of debian. 

Source: Docker docs

You can see the list of all downloaded images by running the command “docker images”. You can read more about the docker pull command here.

docker run

Source: Docker docs

docker run command will create a writable container and run the mentioned command inside the new container. More details about docker run and its options can be viewed in the official documentation.

A popular docker run command is to attach the local console to the container’s terminal. This helps in directly running the commands on the container without explicitly mentioning docker run every time. 

For example, 

Source: Docker docs

This command will pull the ubuntu image from the docker registry if it is not already downloaded. It will also start a new container if it does not exist already. 

The container will execute the /bin/bash command within it and attach the shell output to our terminal. This helps input commands directly to the container’s shell.

Other important Docker concepts

You may occasionally come across some other Docker concepts while working with it. Let us look at them as well.

Docker Compose

Docker Compose helps in running multi-container Docker applications. These containers can be configured to have different application services. The application environment is defined in a Dockerfile. A YAML file called docker-compose.yml is used to define the necessary services.

docker compose up 

docker compose up is the single command required to start the entire application and its services on all containers.

Docker Swarm

Docker Swarm is an orchestration tool to manage a cluster of Docker nodes. A Swarm will have manager nodes and worker nodes. The manager node manages the cluster and sends commands to the worker nodes. Worker nodes receive and execute the tasks given by the manager nodes.

Source: Docker Swarm docs

Docker Desktop

Source: Docker

Docker Desktop is an application that helps in creating containerized applications and sharing them. It provides an intuitive interface for users to design and build a docker-based application. 

Internally, Docker desktop contains all the developer tools and also Kubernetes for orchestration. It uses Docker Hub to get secure images from the repository. 

Installing docker

Now that we understand how Docker works and know about the main components/terminologies of Docker, we can look at installing Docker on our systems. 

If you are a beginner, Docker Desktop is the easiest way to get started with using Docker. Installing Docker desktop is pretty straightforward. The application is available for Linux, Mac and Windows. You can download the installer from here.

In the next blog, we will get into the details of how to create and run your own container image.

Taikun – Container Orchestration at your fingertips

Once you start using containers in your environments, you will need to build, manage and destroy large numbers of containers. These containers will be spread across public, private and hybrid cloud.

This is where container orchestration becomes a necessity. Kubernetes is one of the most important tools for container orchestration. 

Just like Docker Desktop simplifies orchestration of docker nodes, Taikun provides an intuitive interface to manage your container deployments across cloud infrastructures from a single dashboard.

 

It is important to start your container journey on the right foot. Taikun can help you get container management right.