Let’s talk about Docker. As you have read in earlier blogs.
What exactly docker is?
Now let’s talk about the next question, What makes Docker so attractive & how does it work ??
Around 10 Years ago, when the virtual machines started, we realized that virtual machines shared the same hardware with the base machine.
The goal of virtual machines was to ensure that if one failed, then it wouldn’t impact the host. Additionally, they provided isolated environments for various applications.
In short, a virtual machine is a resource through which we can create an elusion for the app that has its own environment.
But even at that time base machine had an enormous load of various virtualized machines, to overcome this situation a new application was launched named ‘docker’.
It is a very lightweight application and shares the kernel with the base machine in other words it virtualized the environment rather than virtualizing a machine.
The main thing I would like to share with you is we have to install the Docker application and then we can run 10-15 containers or more than that on the single base machine without any problem.
Like in our Laptop, we can’t install 10-15 virtual machines as various applications need their own environment.
So, on your laptop, if there is docker installed, then you can work very easily anywhere around the world. However, It does not have any dependency issues.
Docker containers can use their own ports, allowing two containers with Apache on port 80 to run on different ports simultaneously.
[DOCKER IN DOCKER’s TERM…]
BUILD ONCE, CONFIGURE ONCE & RUN ANYWHERE……..
There is also one more component in docker DOCKER INDEX….
You must be thinking about what the Docker index is.
Let’s talk about the docker index, it is basically a git repository that contains docker containers and all. You can push containers in that repository or pull containers just like git.
These all points make Docker so attractive….
Now let’s talk about how does docker work?
Let me tell you one thing Docker’s commands are too simple and user-friendly. You only just need to understand the flow of its commands.
ok, let’s install docker in your ubuntu os machine….
First, open the terminal and go to the root user by typing:
1 |
sudo -s |
then update your system by typing:
1 |
apt-get update |
Now check curl if it is not installed then type:
1 |
apt-get install curl |
Get the latest Docker package with the mentioned command:
1 |
curl -sSL https://get.docker.com/ | sh |
now verify whether the Docker is installed or not, type:
1 |
docker --version |
docker version should be 20.10.22.
[Note: you can get lots of ways to install docker in just a few commands but to install an updated version, follow the procedure.]
Now let’s learn how to run the docker
First, you have to download the docker’s image like I want to download the ubuntu-20.04 image then download it by typing:
1 |
docker pull ubuntu:20.04 |
it will pull the image from the dockerhub
After pulling it, you can list the images by typing:
1 |
docker images |
Then, it will show you the complete downloaded images that you have in your system
after that just hit the command to use docker’s image:
1 |
docker run -i -t ubuntu:20.04 |
The command gives you a terminal to run or install anything. To save changes, you must commit the container by opening another terminal and typing as the root user:
1 |
docker commit your_container_id your_container-name |
now the question arises how do we get to know the container’s ID & container’s name?
Here, you can check your container’s ID and name by typing:
1 |
docker ps |
after committing it, your container is ready to use.
[ Note: Remember, don’t exit or run another container without committing your changes, or you’ll lose your work. Use docker commit
to save your changes. ]
now if you want to run your container in daemonize mode then you have to hit the command:
1 |
docker run -i -d container_name |
To stop running the container:
1 |
docker stop container_id |
To remove the container:
1 |
docker rm container-id |
All basic commands are:
1 |
attach:-Attach to a running containerit |
Terminologies –
- build:-Build a container from a Dockerfile
- commit:-Create a new image from a container’s changes
- cp:-Copy files/folders from the container’s filesystem to the host path
- diff:-Inspect changes on a container’s filesystem
- events:-Get real-time events from the server
- export:-Stream the contents of a container as a tar archive
- history:-Show the history of an image
- images:-List images
- import:-Create a new filesystem image from the contents of a tarball
- info:-Display system-wide information
- insert:-Insert a file in an image
- inspect:-Return low-level information on a container
- kill:-Kill a running container
- load:-Load an image from a tar archive
- login:-Register or Login to the docker registry server
- logs:-Fetch the logs of a container
- port:-Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
- ps:-List containers
- pull:-Pull an image or a repository from the docker registry server
- push:-Push an image or a repository to the docker registry server
- restart:-Restart a running container
- rm:-Remove one or more containers
- rmi:-Remove one or more images
- run:-Run a command in a new container
- save:-Save an image to a tar archive
- search:-Search for an image in the docker index
- start:-Start a stopped container
- stop:-Stop a running container
- tag:-Tag an image into a repository
- top:-Lookup the running processes of a container
- version:-Show the docker version information
- wait:-Block until a container stops, then print its exit code
In the next blog, you can learn how to host a website on a Docker container.
You may also visit our Magento development services and quality Magento 2 Extensions.
For further help or queries, please contact us or raise a ticket.