Day 16 Task: Docker for DevOps Engineers

Day 16 Task: Docker for DevOps Engineers

Table of Content Docker

ยท

5 min read

1. ๐Ÿณ Docker Basics

  • 1.1 What is Docker?

  • 1.2 Dockerfile

2. โš™๏ธ How Docker Works

  • 2.1 Client-Server Architecture

  • 2.2 Docker Image

3. ๐Ÿ“ฆ Docker Components

  • 3.1 Docker Container

  • 3.2 Docker Hub

4. ๐Ÿ› ๏ธ Docker Tools

  • 4.1 Docker Commands

5. ๐Ÿ”„ Docker Integration

  • 5.1 Install Docker On Ubuntu

6. ๐ŸŒ Examples and Conclusion

  • 6.1 Sample Example: Containerizing Application Using Docker

  • 6.2 Pushing an image to Docker Hub

  • 6.3 Conclusion


โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ1. ๐Ÿณ Docker Basicsโ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

What is Docker?

Docker is an open-source containerization platform by which you can pack your application and all its dependencies into a standardized unit called a container. Containers are light in weight which makes them portable and they are isolated from the underlying infrastructure and from each other container. You can run the docker image as a docker container in any machine where docker is installed without depending on the operating system.

Docker is popular because of the following:

  1. Portability.

  2. Reproducibility.

  3. Efficiency.

  4. Scalability.

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ **What is Dockerfile?**โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

The Dockerfile uses DSL (Domain Specific Language) and contains instructions for generating a Docker image. Dockerfile will define the processes to quickly produce an image. While creating your application, you should create a Dockerfile in order since the Docker daemon runs all of the instructions from top to bottom.

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎโš™๏ธ How Docker Worksโ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

โ˜†โ˜†Client-Server Architectureโ˜†โ˜†

Docker Architecture

Docker makes use of a client-server architecture. The Docker client talks with the docker daemon which helps in building, running, and distributing the docker containers. The Docker client runs with the daemon on the same system or we can connect the Docker client with the Docker daemon remotely. With the help of REST API over a UNIX socket or a network, the docker client and daemon interact with each other. To know more about working of docker refer to the Architecture of Docker.

โ˜†โ˜†Docker Imageโ˜†โ˜†

It is a file, comprised of multiple layers, used to execute code in a Docker container. They are a set of instructions used to create docker containers. Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the dependencies required to run the application. The application runs quickly and reliably from one computing environment to another.

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ๐Ÿ“ฆ Docker Componentsโ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

โ˜†โ˜†Docker Containerโ˜†โ˜†

Docker container is a runtime instance of an image. Allows developers to package applications with all parts needed such as libraries and other dependencies. Docker Containers are runtime instances of Docker images. Containers contain the whole kit required for an application, so the application can be run in an isolated way. For eg.- Suppose there is an image of Ubuntu OS with NGINX SERVER when this image is run with the docker run command, then a container will be created and NGINX SERVER will be running on Ubuntu OS.

โ˜†โ˜†Docker Hubโ˜†โ˜†

Docker Hub is a repository service and it is a cloud-based service where people push their Docker Container Images and also pull the Docker Container Images from the Docker Hub anytime or anywhere via the internet. Generally it makes it easy to find and reuse images. It provides features such as you can push your images as private or public registry where you can store and share Docker images

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ ๐Ÿ› ๏ธ Docker Toolsโ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

โœฎโœฎDocker Commandsโœฎโœฎ

There are โ€œnโ€ no.of commands in docker following are some of the commands mostly used.

  1. Docker Run

  2. Docker Pull

  3. Docker PS

  4. Docker Stop

  5. Docker Start

  6. Docker rm

  7. Docker RMI

  8. Docker Images

  9. Docker exec

  10. Docker Login

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ๐Ÿ”„ Docker Integrationโ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

Install Docker On Ubuntu

1. Remove old version of Docker

$ sudo apt-get remove docker docker-engine docker.io containerd runc

2. Installing Docker Engine

$ sudo apt-get update
$ sudo apt-get install docker.io
$ sudo groupadd docker
$ sudo usermod -aG docker ubuntu

Check if docker is successfully installed in your system

$ sudo docker run hello-world

Hands-On: Docker Commands ๐Ÿš€

Task 1: Run a Docker Container

docker run hello-world

Task 2: Inspect Container or Image

docker inspect <container_id_or_image_name>

Task 3: List Port Mappings for a Container

docker port <container_id_or_name>

Task 4: View Resource Usage Statistics

docker stats <container_id_or_name>

Task 5: View Processes Inside a Container

docker top <container_id_or_name> ๐Ÿ‘€

Task 6: Save an Image to a Tar Archive

docker save -o image_archive.tar <image_name>

Task 7: Load an Image from a Tar Archive

docker load -i image_archive.tar

โ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎConclusionโ”€โ”€โ”€ โ‹†โ‹…โ˜†โ‹…โ‹† โ”€โ”€โœฉยฐ๏ฝกโ‹†โธœ ๐ŸŽงโœฎ

Today's exploration took us deep into the heart of Docker, covering essential topics from its fundamentals to hands-on commands. ๐Ÿงญ In our journey, we immersed ourselves in Docker's core concepts, bridging theory with hands-on experience. ๐Ÿš€ We sailed through the Docker seas, unraveling the magic of containers, Dockerfiles, and orchestration. โš“ Navigating through this transformative Docker adventure, we invite you to join us in decoding the enchanting Dockerverse! ๐ŸŒโœจ #DockerDiscovery #HandsOnLearning #DockerJourney ๐Ÿณ

ย