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.

k9ROaBp5v3 UlHCbitg2mwOIbbYS6NV4bTrSNjmp9dLFJarHudj7TPV4oibSjRmf30SFGAYa39SZ5VpRNRYR57

Let us now go through each component of the architecture.

Docker server daemon : dockerd

k9ROaBp5v3 UlHCbitg2mwOIbbYS6NV4bTrSNjmp9dLFJarHudj7TPV4oibSjRmf30SFGAYa39SZ5VpRNRYR57

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

k9ROaBp5v3 UlHCbitg2mwOIbbYS6NV4bTrSNjmp9dLFJarHudj7TPV4oibSjRmf30SFGAYa39SZ5VpRNRYR57

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. 

k9ROaBp5v3 UlHCbitg2mwOIbbYS6NV4bTrSNjmp9dLFJarHudj7TPV4oibSjRmf30SFGAYa39SZ5VpRNRYR57

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.

YAOwIX4pmQxDRfoQeQWENghE0IUHAfQTXAKnJT6ha3xN3axMbvgogXSsngohKlzNI1jJUWEgnXXnqVwMHnGBczydlmnbg5KMtvn fH8VW xBUHZeqR92j8wAWTE1IS gaY3rCgQuuXDTYEHGBHrx

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.

WluQDGHVUKGmcjd9yPslDy1 Hh2Nan s Z0f8rS1f6Nclf4pUJTKiLOOTYzezKZscsHsayusyBHnowHAkHX7ljGYkGUO0Ahdl8xSl7uTKSoV5J3SUwJUqO7CLhFmW831tNEK 0cS3 Cbx3oucf0oT9WVbUb7UcOorbRX7LKWMi bghcMNnA

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

k9ROaBp5v3 UlHCbitg2mwOIbbYS6NV4bTrSNjmp9dLFJarHudj7TPV4oibSjRmf30SFGAYa39SZ5VpRNRYR57

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.

vfobq93HA pWbKzKAtfS4eUhhRaMTpjoKzTDo1aCp hUKUwRWVJPswDRdkiRFYMiJ2WIV f1PDygYG1ZYepuedXjsBxMnju0hSnTADN2J9mbGizVmL3

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, 

8USvSGl4PCroK9ZXAUp2LIXWo taHQRG6DLjFSnLrAZIOShzuUyM0U7AZD87OtwjUdd5MZkqZQsgsQPiMZxuTishTKUD7CKZ5sKfmQky vf18SvsIR4l0PHwFTIlHqfMDBeFtPpC75JW9NmeCYERXe2YUu2oj8INnZ9lFL5Y rcOuC6CIA

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. 

abIZcUtP93GfzuNriSsWeF4gU3YPgRYEPvZFDWbpZ17 b2x l PtblfohYV7 Fw8oVzr4ifkjfBISC5g5noNW1413K cv aa0ttrymijt6pKaRX3BaUnCAwExkMxx2mypIIpE 3ePhImiDKY3e gDp9 pl4zkjhu8tWNyDN7OCEG9mHYlMg

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

MvY3LInzhcrwhIk YKrzrXUJhTHtlCw8NBTG0CYpTUQZR bY qkgLVyHzL377Z0afcXOjeQGoyttvH6SLzcUU1fcE6 D

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, 

FZ2iOmU3OVCNoCXbrHzV1W

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.

wo2OyOEv0IfUhLHVderPMX3HqeOHfpIcTjbxz6QVynqvV1DUvX9CXsCZyhXEEMjU0BGSL kxKYqPcPzsoMug Xfk2Y

Docker Desktop

Vgf6XaD7GxZH GQPqFDLuzWMgpryLuj3NVgJp6IYNHRT7LZaAneuVLriWJ9xnrfwKIvfJpem6jikxpXcbgU4kPLPI1AahmT4jMHwbR9D KNAO86uxfHnWol jLr

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. 

TKoCLkT1JtF 5juEgQMWsOaA2W2YzPUHV5oG8KPR0 El GKFYPvWr7Hevg VV8mNHk eoPtQ0pRMq752mqs5tzUJvPAZe6aJG3bjs2uz899OHY fYV qoaThXJaGwgDv ibNj0NTpyPwgv7MHVDGViyF6WyEj NLZVoHekc74QPdytdPSEM

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

Try it now for FREE         Schedule a call with us