Learn Docker (Part 1-Introduction to Docker with installation)

rahmatei
4 min readOct 21, 2023

--

In the first part, we introduce some basic concepts and how to install it on debian dist, and after installation, we take a general test to see if our docker is ready or not. In the next part, we go to the basic docker commands.

It should be noted that some of the definitions are taken from the Docker site itself at https://www.docker.com/

Docker is an open-source platform for managing and running applications in isolated environments known as containers. This technology allows you to operationalize your applications as containers, which contain all the necessary dependencies for execution. Docker, developed by Docker Inc., offers benefits such as isolation, easy portability between environments, and simplified management. It is widely used in software development and system administration.

Docker Object

When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.

Image:

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.
You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image.

When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.

Containers

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

It is the process of encapsulating software code along with all of its dependencies inside a single package so that it can be run consistently anywhere

Docker Registry

Docker registry is the place where Docker images are stored.

Docker Hub is a public registry that anyone can access & configure images
Registry can be on public or local repository

Docker Hub Address : https://hub.docker.com/explore/

Install Docker Engine on Debian

Before you can install Docker Engine, you must first make sure that any conflicting packages are uninstalled.

Run the following command to uninstall all conflicting packages:

Here we clear the packages with a For loop

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

Images, containers, volumes, and networks stored in /var/lib/docker/ aren’t automatically removed when you uninstall Docker

To Unistall data completely
https://docs.docker.com/engine/install/debian/#uninstall-docker-engine

Install using the Apt repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker Apt repository. Afterward, you can install and update Docker from the repository.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install the Docker packages

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the installation is successful by running the hello-world image:

$ docker run hello-world

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

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

You have now successfully installed and started Docker Engine

Install using the convenience script

The script requires root or sudo privileges to run.
By default, the script installs the latest stable release of Docker, containerd, and runc.

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run

--

--