Table of contents
- Before Docker, What usually happens?
- What is a virtual machine and how does it solve the one application on one server problem?
- What is a container? Container vs virtual machine?
- What is Docker and parts of Docker?
- Docker file and Docker image.Creating a simple docker image.
- List of docker commands
- Explanation to docker-compose.
- Docker compose vs Kubernetes vs docker swarm.
- Docker-volume
Before Docker, What usually happens?
At the beginning of the Internet thing, applications are run basically on the server. The problem was if the server load is increased we have to get new servers so this was not so cool. The idea is you can't run multiple applications on one server means One application = One server. It was very time and cost-consuming.
Who solves this problem? At that time there was a company named VM-WARE that comes into picture as Virtual machine.
What is a virtual machine and how does it solve the one application on one server problem?
A virtual machine (VM) is a software emulation of a physical computer system. It enables you to run multiple operating systems or applications on a single physical machine, allowing for better utilization of hardware resources and increased flexibility.
A virtual machine consists of two main components: the host machine and the guest machine. The host machine is the physical computer that runs the virtualization software, also known as the hypervisor. The hypervisor provides a layer of abstraction between the physical hardware and the virtual machines, managing the resources and facilitating communication between them.
The virtual machine concept is not satisfactory. It is better than before but not you know very efficient because it needs a dedicated amount of hard disk and storage from the host operating system. So, to solve this problem comes into the picture one of the popular platform called Docker.
What is a container? Container vs virtual machine?
In Docker, a container is a lightweight and isolated execution environment that encapsulates an application along with its dependencies. It allows you to package software in a standardized unit, which includes everything needed to run the application, such as the code, runtime, system tools, system libraries, and settings.
What is Docker and parts of Docker?
Docker is an open-source platform that enables developers to automate the deployment, scaling, and management of applications using containerization. It provides a way to package applications and their dependencies into lightweight, isolated containers that can run consistently across different environments.
In simple terms, Docker is the container platform that helps to manage our containers.
Parts of docker:
- Run Time:
Its role is to start and stop the container. Runtime is of two times as Run C (as low level) and Container D (as high level). Run c works with the operating system and helps to start and stop the container. Container D is a CNCF project and its role is to manage Run C and interact with networking like pulling the image.
- Docker Engine:
Docker Engine (Daemon) is used to communicate with the docker container.
- Orchestration
Docker itself is primarily a containerization platform, rather than a full-fledged orchestration engine. However, Docker can be integrated with various container orchestration tools to manage large-scale deployments of containers across multiple hosts, automate scaling, and load balancing, and ensure high availability. One such popular orchestration engine is Kubernetes.
Docker file and Docker image.Creating a simple docker image.
A Dockerfile is a text file that contains a set of instructions used to build a Docker image. These instructions specify the base image, environment variables, dependencies, and steps to be executed during the image build process.
A Docker image is an executable software package that includes everything needed to run an application. It serves as a template for creating and running containers in DockerDocker images built using a declarative specification file called Dockerfile. First of all, create a separate directory and Create the Dockerfile inside that directory using vi Dockerfile
command then write your docker file in the vim editor.
FROM ubuntu
CMD ["echo", "Hey this is simple demo to create own image"]
Then run the below command to create the image from the above docker file
docker build -t my-image:1.0 .
Basically, this command means building my image with the image name "my-image" and version 1.0 from the Docker file situated in the current directory.
List of docker commands
docker start container_id
: It will start your container.docker stop container_id
: It will stop your container.docker ps
: It will show all the stopped containers.docker ps -a
: It shows all the running containers.docker run image_name
: It starts the container from image.docker rm container_id:
It will delete your container.docker container prune -f
: It will delete all the stopped containers.docker rmi image_id:
It deletes the image.docker inspect container_id:
It shows more and more information about your container.docker container exec -it container_id /bin/bash
: This command helps to attach with the container.docker run -d alpine ping www.google.com
: It will run your container in detached mode means background.docker logs container_id
: It shows the information logged by the running container.docker pull image_name
: It pulls the image from the docker hub.docker build -t image_name:
It builds the image from the docker file.docker-compose up:
It will create and start the container defined in compose file.docker-compose down:
It will Stop and remove containers defined in a Compose file.docker network ls
: It lists all the available docker networks.docker network create network_name
: Creates the new network.
Explanation to docker-compose.
Docker Compose is a tool provided by Docker that allows you to define and manage multi-container applications. It uses a YAML file to configure the services, networks, and volumes required for your application's setup. With Docker Compose, you can easily define, configure, and run multiple Docker containers as a single application stack.
Here are some key features and benefits of using Docker Compose:
Declarative Configuration
Multiple Container Management:
Service Dependencies:
Easy Application Scaling
To use Docker Compose, you need to define a docker-compose.yml
file that describes your application's services, networks, and volumes. Once you have defined the file, you can use the docker-compose
command-line tool to start, stop, and manage your application stack based on the configuration specified in the YAML file.
Docker compose vs Kubernetes vs docker swarm.
Docker Compose, Docker Swarm, and Kubernetes are all container orchestration tools that serve different purposes and cater to different deployment scenarios. Here's a brief comparison of these tools:
Docker Compose: Docker Compose is suitable for small to medium-sized deployments where you want to define and manage multiple containers as a single application stack on a single host machine.
Docker Swarm: Docker Swarm is suitable for deploying and managing containerized applications in a clustered environment, allowing you to scale and distribute your application across multiple nodes for high availability and load balancing.
Kubernetes: Kubernetes is a powerful open-source container orchestration platform. It is suitable for large-scale deployments and complex containerized applications. It excels in managing highly available, fault-tolerant, and scalable production environments with features like pod scheduling, resource management, and horizontal auto-scaling.
Docker-volume
In Docker, a volume is a directory or a designated storage area that is managed by Docker and is used to persist data generated by containers. Volumes provide a way to store and share data between containers or between the host machine and containers.
To work with volumes, you can use Docker commands such as docker volume create
to create a named volume, docker volume ls
to list available volumes, and docker volume rm
to remove a volume. Additionally, volumes can be specified in Docker Compose files using the volumes
section.
Using volumes in Docker provides a convenient way to handle data persistence and sharing, making it easier to manage stateful applications and separate data from the container lifecycle.