Welcome to Day 16 of our DevOps journey! Today we will learn about the exciting world of Docker and explore its significance for DevOps engineers. In this article, we will uncover the fundamentals of Docker, its role in enabling efficient software deployments, and how it empowers DevOps teams to streamline their workflows and enhance collaboration.
❄What is Docker?
Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
❄Containers and virtual machines have the same goal: application separation (Application) and library (Library), including files. The relevant data is stored in a box that can be deployed on a host anywhere, but both containers and virtual machines have different architectures.
❄Virtual Machine virtualizes the entire computer. And run the program like a real computer. Virtual Machine will use Hypervisor to run, which can run on Hardware/Infrastructure directly or can run on the operating system (OS) at all
❄Hypervisor that runs on the operating system (Hosted Hypervisor), including VMware Workstation, Microsoft Virtual PC and Oracle Virtual Box, etc.
❄Bare-metal Hypervisors include VMware ESX, Citrix Xen Server, and Microsoft Hyper-V, among others.
❄Containers differ from Virtual Machines in that Virtual Machines are hardware virtualizations while containers are OS (Operating System Virtualization) simulations, which allows each container running on the same Host to share a common System Kernel.
❄❄❄Let’s take a look at Docker components❄❄❄
1)Docker Engine: At the core of Docker is the Docker Engine, also known as the Docker daemon. It is a lightweight and powerful runtime that runs and manages containers. The Docker Engine performs tasks such as building, running, and distributing containers, making it the heart of the Docker ecosystem.
2) Docker Images: A Docker image is a lightweight, standalone, and executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, dependencies, and system tools. Images serve as the building blocks for containers and are created from a set of instructions called Dockerfiles.
3) Docker Registry: The Docker Registry is a centralized repository that stores Docker images. It serves as a distribution mechanism for sharing and pulling images across different environments. The default public registry is Docker Hub, which hosts a vast collection of pre-built images. Additionally, organizations can set up private registries to store proprietary or customized images.
4) Docker Compose: Docker Compose is a tool that allows defining and managing multi-container applications. It uses a YAML file to specify the services, networks, and volumes required for a complex application. With Docker Compose, you can spin up multiple containers, link them together, and configure their interactions, making it easier to orchestrate and manage the application stack.
5) Docker Containers: A Docker container is a running instance of a Docker image. Containers provide an isolated environment where applications can run consistently across different systems and platforms. Each container has its own file system, network interfaces, and process space, ensuring that applications are isolated from one another.
❄Why Docker is needed for DevOps Engineer?
Docker is essential for DevOps engineers because it offers:
1. Containerization and Portability: Docker packages applications and their dependencies into self-contained units, ensuring consistent execution across different environments.
2. Streamlined Deployment and Scalability: Docker simplifies deployment processes and enables efficient scaling with container orchestration tools like Docker Swarm or Kubernetes.
3. Faster and Reproducible Development Workflow: Docker creates reproducible development environments, reducing setup time and troubleshooting efforts.
4. CI/CD Integration: Docker seamlessly integrates into CI/CD pipelines, automating build, test, and deployment processes.
5. Collaboration and Isolation: Docker fosters collaboration between teams by providing consistent environments and isolating dependencies.
❄❄❄Tasks❄❄❄
As you have already installed docker in previous days tasks, now is the time to run Docker commands.
❄1 :- Use the docker run
command to start a new container and interact with it through the command line.
docker run command is used to create a new container.
command - docker run -d <image-name or ID> here -d is a detached mode.
To create a container with a container name:
command - docker run -d --name <container-name> <image-name>
To create a container with a port number:
command - docker run -d -p 8080:80 <image-name>
- Create a container with a name and port number :-
❄2 :- Use the docker inspect command to view detailed information about a container or image.
docker inspect :- It is a command that returns detailed, low-level information on Docker objects. Those objects can be docker images, containers, networks, volumes, plugins, etc. By default, docker inspect returns information in JSON format.
❄3 :- Use the docker port command to list the port mappings for a container.
command - docker port <container-name>
docker port Container-name [PRIVATE_PORT[/PROTO]]
❄4 :- Use the docker stats command to view resource usage statistics for one or more containers.
docker stats : The docker stats command returns a live data stream for running containers. To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data.
command: docker stats
command - docker stats [options] [containers...]
Options:
--all , -a: Show all containers (default shows just running).
--format: Pretty print images using a Go template.
--no-stream: Disable streaming stats and only pull the first result.
--no-trunc: Do not truncate output.
❄5 :- Use the docker top command to view the processes running inside a container.
docker top :- Display the running processes of a container.
command :- docker top <container>
❄6 :- Use the docker save command to save an image to a tar archive.
docker save :- Save one or more images to a tar archive
command :- docker save [options] [image]
option :- --output , -o :- Write to a file, instead of STDOUT
Method :- 1
Method :- 2
❄7. Use the docker load command to load an image from a tar archive.
command : docker load [options]
options:
--input , -i : Read from tar archive file, instead of STDIN
--quiet , -q : Suppress the load output.
Method :- 1
Method :- 2