Docker š³
Docker is a set of platforms as a service (PaaS) products that use the 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.
Difference between Docker Containers and Virtual Machines
1. Docker Containers
Docker Containers contain binaries, libraries, and configuration files along with the application itself.
They donāt contain a guest OS for each container and rely on the underlying OS kernel, which makes the containers lightweight.
Containers share resources with other containers in the same host OS and provide OS-level process isolation.
2. Virtual Machines
Virtual Machines (VMs) run on Hypervisors, which allow multiple Virtual Machines to run on a single machine along with its own operating system.
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.
They provide Hardware-level process isolation and are slow to boot.
Important Terminologies in Docker
1. 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.
2. Docker Container
It is a runtime instance of an image.
Allows developers to package applications with all parts needed such as libraries and other dependencies.
3. Docker file
It is a text document that contains necessary commands which on execution helps assemble a Docker Image.
Docker image is created using a Docker file.
4. Docker Engine
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.
5. Docker Hub
Docker Hub is the official online repository where you can find other Docker Images that are available for use.
It makes it easy to find, manage, and share container images with others.
Installing Docker on Ubuntu
1. Remove old version of Docker
2. Installing Docker Engine
Check if docker is successfully installed in your system
Create an application in Docker
1. Create a folder with 2 files (Dockerfile and main.py file) in it.
Dockerfile
2. Edit main.py with the below code.
#!/usr/bin/env python3
print("Docker and GFG rock!")
3. Edit Dockerfile with the below commands.
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.
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.
Push an image to Docker Hub
1. Create an Account on Docker Hub.
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:
The above will give us this result
Image ID is used to tag the image. The syntax to tag the image is:
4. Push image to Docker Hub repository
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.
2. Now run the image, it will fetch the image from the docker hub if it doesnāt exist on your local machine.
Conclusion:
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.