Docker is a set of platforms as a service (PaaS) products that use Operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than a virtual machine.
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:
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.
- It is a text document that contains necessary commands which on execution help assemble a Docker Image.
- Docker image is created using a Docker file.
Dockerfile is the source code of the image
To Know more about the Dockerfile refer to the Docker – Concept of Dockerfile.
How Docker Works
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.
What is 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.
What is 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.
What is 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
Mainly DevOps team uses the Docker Hub. It is an open-source tool and freely available for all operating systems. It is like storage where we store the images and pull the images when it is required. When a person wants to push/pull images from the Docker Hub they must have a basic knowledge of Docker. Let us discuss the requirements of the Docker tool.
What is Docker Compose?
Docker Compose will execute a YAML-based multi-container application. The YAML file consists of all configurations needed to deploy containers Docker Compose, which is integrated with Docker Swarm, and provides directions for building and deploying containers. With Docker Compose, each container is constructed to run on a single host.
How to Download Docker Desktop?
Docker Desktop provides GUI to work on docker containers, docker images and docker networks. Docker desktop provides and separate environment which contains Docker Engine, Docker CLI, Docker Compose, Kubernetes, and other tools whcih are needed to build,ship and run the applications in the form of containerization which make it more user friendly. To know more how to install docker desktop refer to Docker Desktop Sample Image.
There are “n” no.of commands in docker following are some of the commands mostly used.
- Docker Run
- Docker Pull
- Docker PS
- Docker Stop
- Docker Start
- Docker rm
- Docker RMI
- Docker Images
- Docker exec
- Docker Login
To Know more about the docker commands refer tot the Docker – Instruction Commands.
The software that hosts the containers is named Docker Engine. Docker Engine is a client-server based application. The docker engine has 3 main components:
- Server: It is responsible for creating and managing Docker images, containers, networks, and volumes on the Docker. It is referred to as a daemon process.
- REST API: It specifies how the applications can interact with the Server and instructs it what to do.
- Client: The Client is a docker command-line interface (CLI), that allows us to interact with Docker using the docker commands.
Why use Docker
Docker can be used to pack the application and its dependencies which makes it lightweight and easy to ship the code faster with more reliability. Docker make every simple to run the application in the production environment docker container can be platform independent if the docker engine is installed in the machine.
What is Docker For AWS?
Docker is the most powerful tool to run the application in the form of containers. Docker container are light in weight and can be run on any operating system.
AWS provides the Amazon Elastic Container Service (Amazon ECS) it is an fully managed container service by which you can deploy, scale and manage the docker containers. Amazon ECS is the most reliable platform according to the performance and also it can be integrated with the other AWS Service like load balancing, service discovery, and container health monitoring. To know more about Amazon Elastic Container Service (Amazon ECS).
Difference Between Docker Containers and Virtual Machines
Docker Containers contain binaries, libraries, and configuration files along with the application itself.
Virtual Machines (VMs) run on Hypervisors, which allow multiple Virtual Machines to run on a single machine along with its own operating system.
They don’t contain a guest OS for each container and rely on the underlying OS kernel, which makes the containers lightweight.
Each VM has its own copy of an operating system along with the application and necessary binaries, which makes it significantly larger and it requires more resources.
Containers share resources with other containers in the same host OS and provide OS-level process isolation.
They provide Hardware-level process isolation and are slow to boot.
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 \
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
Check if docker is successfully installed in your system
$ sudo docker run hello-world
Sample Example: Containerizing Application Using Docker
1. Create a folder with 2 files (Dockerfile and main.py file) in it.
2. Edit main.py with the below code.
"Docker and GFG rock!"
3. Edit Dockerfile with the below commands.
COPY main.py /
CMD [ "python", "./main.py" ]
4. Create a Docker image.
Once you have created and edited the main.py file and the Dockerfile, create your image to contain your application.
$ sudo docker build -t python-test .
The ‘-t’ option allows to define the name of your image. ‘python-test’ is the name we have chosen for the image.
5. Run the Docker image
Once the image is created, your code is ready to launch.
$ sudo docker run python-test
Sample Example to Push an image to Docker Hub
1. Create an account on Docker Hub or use an existing one if you already have one.
2. Click on the “Create Repository” button, put the name of the file, and click on “Create”.
3. Now will “tag our image” and “push it to the Docker Hub repository” which we just created.
Now, run the below command to list docker images:
$ docker images
The above will give us this result
REPOSITORY TAG IMAGE_ID CREATED SIZE afrozchakure/python-test latest c7857f97ebbd 2 hours ago 933MB
Image ID is used to tag the image. The syntax to tag the image is:
docker tag <image-id> <your dockerhub username>/python-test:latest
$ docker tag c7857f97ebbd afrozchakure/python-test:latest
4. Push image to Docker Hub repository
$ docker push afrozchakure/python-test
Fetch and run the image from Docker Hub
1. To remove all versions of a particular image from our local system, we use the Image ID for it.
$ docker rmi -f af939ee31fdc
2. Now run the image, it will fetch the image from the docker hub if it doesn’t exist on your local machine.
$ docker run afrozchakure/python-test
So you have learned about the basics of Docker, the difference between Virtual Machines and Docker Containers along some common terminologies in Docker. Also, we went through the installation of Docker on our systems. We created an application using Docker and pushed our image to Docker Hub. Lastly, we learned how we could remove a particular image from our local system and later pull the image from Docker Hub if it doesn’t exist locally.
Frequently Asked Questions (FAQs) On Docker:
Q1: What is Docker Hub in short?
Docker Hub is a public registry where user/developers can store and share system images created by them and making them to easily access and reuse images for other software developers.
Q2: What is needed to use Docker Hub?
To use Docker Hub user should have an account on Docker Hub platform. If you don’t have an account on Docker Hub you can create one by singing up. Once you have an account on Docker, then you can perform operations like push and pull images to and from Docker Hub.
Q3: What are the benefits of Docker?
Portability -Runs on Any machine
Isolation -Containers are isolated from each other
Reproducibility -Images can easily be accessed and reused.
Resource Efficiency -Containers share the host machine’s kernel which improves performance.
Q4: What are Docker Logs?
Docker daemon and Docker containers will generate the docker logs in the form of text messages which will helps you in further to troubleshoot problems, monitor the performance of your applications, and gather information about the state of your Docker environment.
Q5: What is Docker Build?
Docker build is an command which is used to build the docker image by using the Dockerfile.
Q6: What is Docker Ubuntu?
“Docker Ubuntu” is the term used for utilizing the Docker service with Ubuntu-based operating systems. Running Docker is best suited for the popular Linux distribution Ubuntu.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!