A Beginner’s Guide to Docker
As a toolbox is to a mechanic, so is Docker to a developer or engineer. Are you a beginner in the world of Docker and Containerization? Or are you a software engineer, developer, or devOps engineer, etc., who requires an understanding of Docker to deploy pipelines and manage containers at scale? This article will explain to you in simple terms what the concept of Docker is all about. Let’s dive in. What is Docker? Docker is a software platform that allows developers to build, test, and deploy their applications quickly by using containers. It is known worldwide as an open-source container service provider as it provides a standardized way to package, ship, and run applications in containers. A Docker container is a packaging system that packages an application's code and dependencies in a standard format that allows it to run quickly and reliably across computing environments. Docker containers are usually lightweight and contain everything needed to run an application. These include libraries, system tools, code, and runtime. Docker Versus Virtual Machines Virtual machines and Docker containers are both virtualization technologies, but they differ in their approach and resource usage. The differences between them include the following. Virtual machines Docker Virtual machines have a hypervisor layer Docker works by a Docker engine layer. The memory usage is very high because of its additional layers. In Docker environments, the memory usage is very low. As you add more software, performance decreases. Performance is always good because of its light-weight architecture. Portability is difficult. Portability is easier Boot-up time is slow. Boot-up time is fast. Running multiple virtual machines in a single environment can lead to instability and performance issues. Docker is designed to run multiple containers in the same environment. Advantages and Disadvantages of Docker Just like any software or technology, Docker also has it good and bad sides. Let’s talk about the advantages and disadvantages of Docker. Advantages Docker is the most popular containerization tool, with a market share of 82.84%. It offers a lot of advantages, some of which are: It offers a fast and consistent delivery of applications: It streamlines the development lifecycle, ensuring that your applications run the same way through standardized environments. Docker containers allow for highly portable workloads as they can be easily moved and deployed on different environments such as a developer’s local laptop, virtual or physical machines, cloud providers, etc. Docker containers are lightweight, thus making it a better option than hypervisor-based virtual machines. Its portability and lightweight also make it easy to manage workloads, scaling up or tearing down applications as the need arises. Disadvantages of Docker The disadvantages of Docker include: Improper configuration and management of containers can potentially cause issues such as instability and resource contention. Docker containers are more efficient than virtual machines, but they may not be optimal for resource-intensive allocations. Because Docker containers share the host kernel, a vulnerability in one container can affect the entire system. Managing multiple containers and orchestrating them can be quite complex and may require specialized knowledge. It can be difficult to manage large configurations with Docker, as it usually requires additional configuration and management. Why Should You Use Docker As a developer or devOps engineer, you can use Docker to create images that include everything your application needs. Docker also allows you to run these images as containers, isolating your application and its dependencies. You can also share Docker images with others or store them in registries (like Docker Hub) for easy distribution and reuse. In addition to that, Docker gives you the tool and platform for managing the lifecycle of your containers. Its isolation and security let you run many containers simultaneously on a given host. Docker Architecture, Terms, and Tools Docker Host: A Docker host is a physical or virtual machine which runs the docker engine. Docker Image: A Docker image is a read-only template that contains the instructions for creating a Docker container. You can create your images or use those created by others and published in a registry. Docker Registry: A Docker registry is where Docker images are stored. Docker Hub: Docker Hub is a public registry where anyone can look to get a Docker image. By default, Docker looks for images on Docker Hub. Docker Engine: Docker Engine is a client/server application that supports containers on various Windows and Linux operating systems. A Docker engine consists of the Docker daemon, a Docker API that interacts with the daemon, and a command-line interface (CLI) that talks to the daemon
As a toolbox is to a mechanic, so is Docker to a developer or engineer. Are you a beginner in the world of Docker and Containerization? Or are you a software engineer, developer, or devOps engineer, etc., who requires an understanding of Docker to deploy pipelines and manage containers at scale?
This article will explain to you in simple terms what the concept of Docker is all about. Let’s dive in.
What is Docker?
Docker is a software platform that allows developers to build, test, and deploy their applications quickly by using containers. It is known worldwide as an open-source container service provider as it provides a standardized way to package, ship, and run applications in containers.
A Docker container is a packaging system that packages an application's code and dependencies in a standard format that allows it to run quickly and reliably across computing environments.
Docker containers are usually lightweight and contain everything needed to run an application. These include libraries, system tools, code, and runtime.
Docker Versus Virtual Machines
Virtual machines and Docker containers are both virtualization technologies, but they differ in their approach and resource usage. The differences between them include the following.
Virtual machines | Docker |
---|---|
Virtual machines have a hypervisor layer | Docker works by a Docker engine layer. |
The memory usage is very high because of its additional layers. | In Docker environments, the memory usage is very low. |
As you add more software, performance decreases. | Performance is always good because of its light-weight architecture. |
Portability is difficult. | Portability is easier |
Boot-up time is slow. | Boot-up time is fast. |
Running multiple virtual machines in a single environment can lead to instability and performance issues. | Docker is designed to run multiple containers in the same environment. |
Advantages and Disadvantages of Docker
Just like any software or technology, Docker also has it good and bad sides. Let’s talk about the advantages and disadvantages of Docker.
Advantages
Docker is the most popular containerization tool, with a market share of 82.84%. It offers a lot of advantages, some of which are:
- It offers a fast and consistent delivery of applications: It streamlines the development lifecycle, ensuring that your applications run the same way through standardized environments.
- Docker containers allow for highly portable workloads as they can be easily moved and deployed on different environments such as a developer’s local laptop, virtual or physical machines, cloud providers, etc.
- Docker containers are lightweight, thus making it a better option than hypervisor-based virtual machines.
- Its portability and lightweight also make it easy to manage workloads, scaling up or tearing down applications as the need arises.
Disadvantages of Docker
The disadvantages of Docker include:
- Improper configuration and management of containers can potentially cause issues such as instability and resource contention.
- Docker containers are more efficient than virtual machines, but they may not be optimal for resource-intensive allocations.
- Because Docker containers share the host kernel, a vulnerability in one container can affect the entire system.
- Managing multiple containers and orchestrating them can be quite complex and may require specialized knowledge.
- It can be difficult to manage large configurations with Docker, as it usually requires additional configuration and management.
Why Should You Use Docker
As a developer or devOps engineer, you can use Docker to create images that include everything your application needs. Docker also allows you to run these images as containers, isolating your application and its dependencies. You can also share Docker images with others or store them in registries (like Docker Hub) for easy distribution and reuse.
In addition to that, Docker gives you the tool and platform for managing the lifecycle of your containers. Its isolation and security let you run many containers simultaneously on a given host.
Docker Architecture, Terms, and Tools
Docker Host: A Docker host is a physical or virtual machine which runs the docker engine.
Docker Image: A Docker image is a read-only template that contains the instructions for creating a Docker container. You can create your images or use those created by others and published in a registry.
Docker Registry: A Docker registry is where Docker images are stored.
Docker Hub: Docker Hub is a public registry where anyone can look to get a Docker image. By default, Docker looks for images on Docker Hub.
Docker Engine: Docker Engine is a client/server application that supports containers on various Windows and Linux operating systems. A Docker engine consists of the Docker daemon, a Docker API that interacts with the daemon, and a command-line interface (CLI) that talks to the daemon.
Docker Daemon: This serves as the control center for Docker implementation. Docker daemon is a service that creates and manages Docker images using commands from the client.
Docker Objects: Docker objects are components of Docker, such as images, containers, networks and plug-ins that help to package and distribute applications.
How to Install Docker on Ubuntu 22.04 LTS
Here, I will install Docker on my Ubuntu 22.04 LTS. You can choose to install the Docker Desktop on your Windows OS or Mac directly here. The former has higher performance and uses fewer resources.
Step 1: Update your existing list of packages
sudo apt update
Step 2: Then, install a few prerequisite packages that let apt use packages over HTTPS
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add the GPG key for the official Docker repository to your system
curl -fsSL https://download.Docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/Docker-archive-keyring.gpg
Step 4: Add Docker repository to APT sources
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/Docker-archive-keyring.gpg] https://download.Docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/Docker.list > /dev/null
Step 5: Again, update your existing list of packages for the addition to be recognized
sudo apt update
Step 6: Ensure you install from the Docker repo instead of the default Ubuntu repo
apt-cache policy Docker-ce
Step 7: You will see an output like the one below, meaning that Docker is not installed but the candidate for installation is from the Docker repository for Ubuntu.
Step 8: Install Docker
sudo apt install Docker-ce
Step 9: Check that its running
sudo systemctl status Docker
The output should be something like this;
Congrats, you have successfully installed Docker and it is now running.
Basic Docker Commands
To show the installed Docker version on your system
Docker - - version
To start the Docker daemon
systemctl start Docker
To download or pull an image from Docker hub
Docker pull ‘image name’
To start an existing container
Docker start ‘containerID or name’
To remove a Docker image
Docker rm ‘imageID or name’
To remove a Container
Docker rm ‘ContainerID or name’
To list all images on your machine
Docker images
To run an image
Docker run ‘imagename’
To stop an image/container
Docker stop ‘containerID or name’
If you get stuck
Docker -–help
Whoosh! We have come to the end of this article. I hope this was helpful to you. Do have a good time working with Docker.