Is it possible to run multiple applications in a single Server
Yes, it is possible, but latency and performance is the drawback, hence Virtual Machine concepts using VMware came into picture but still it had some performance issues hence Docker-containerization came into picture.
Please check - Docker vs Virtual Machine (VM) - Understanding the Differences (geekflare.com)
What is Docker registry?
It is a place where all the Docker images of your project are stored using tags.
What is Docker hub?
It is a Cloud based system of Docker registry where you can store, share and test Docker containerized images.
What is a container?
It is a virtualized operating system where you run micro services, small- or large-scale application.
Can I run multiple applications in a single container?
It is possible, the best practice is to run single application per container.
A simple diagram that explains the difference between Virtual Machine Hypervisor and Docker container
Steps involved to install Docker
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install \ca-certificates \curl \gnupg \lsb-release - this command is to allow apt to use a repository over HTTPS
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
the above command is to add the GPG key for official Docker repositorysudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
the above command is used to add the stable repository
- sudo apt-cache policy docker-ce -> this command is to add docker repo
sudo systemctl status docker to check the status of docker
sudo apt-get upgrade
sudo service docker start
sudo usermod -aG docker $USER this command helps you to execute docker commands without using sudo
Create a duplicate session now in your putty and login, close the old session and you can start executing docker commands without using sudodocker info this command lists out the number of containers running, how many of them in stopped state etc
The following are the 4 (four) terminologies involved in DockerDocker host -> Images, Container, Daemon, Volumes
Daemon is the one that helps docker to create containers. It will first check the docker host for the images to run the container else it will fetch images from Docker RegistryDocker Registry -> It can be an OS image or an application image such as nodejs,php
Docker client - > docker build, run, pull, push
Dockerfile -> this is a text file that we can use to create an image and assemble it
Let’s see how to create a basic containerdocker run hello-world (please read the below screenshot carefully, this command first checks whether the hello-world image is available in local registry, its not available so it created a container from the Docker hub… Docker hub is Docker's official cloud-based registry)
- docker run –it ubuntu (this will create an ubuntu container from the image available in docker hub) We can now see the how many containers are created in our machine
- docker ps –a
- Let’s start the container now docker start container-id or docker start container-name For better understanding I created a container using centos using below command docker run centos this create a new container using centos image from docker hub
In the above figure docker ps –a lists out the container status with the container id
To run the container, we can use the container id
docker run c3765e84473a
docker run 5258ae771fba
Let’s check the containers running in our machine, if the container is not being used it will exit
Lets make the containers run now
docker container start c3765e84473a
docker container start 5258ae771fba
docker exec -it 5258ae771fba /bin/bash this command helps to login to a container
Output of above commands -
The command to list out the number of images in our docker machine is
docker images
The command to remove an image available in docker machine is
Docker rmi imagename –force docker rmi hello-world –force
Output -
The command to check images available in dockerhub for a particular OS or application
docker search image name or applicationnanme
docker search php
The command to stop a running container is
docker stop containerid
docker stop 5258ae771fba
The command to start a container
docker start 5258ae771fba
Let’s install apache in our ubuntu container and commit the changes to the ubuntu image in our machine, lets login to the container first and install apache
docker exec –it 5258ae771fba /bin/bash
Lets do a update inside the container
apt-get update
apt-get install apache2
service apache2 start
service apache2 status
Let’s exit the container and take a snapshot of the image in which the container runs with apache2
shiva@hypo-cloudeva:~$ docker commit 5258ae771fba ubuntu-apache-april30-2022
in the above command “ubuntu-apache-april30-2022” this is the snapshot name we are giving for this container/image now
Now a new snapshot of the ubuntu image is taken, you can see in the above snip.
Let’s see how can we map our local machine port with the container port
docker run –p 5000:80 ubuntu-apache-april30-2022
ubuntu-apache-april30-2022 – this is the name of our image that we built from the container
Let’s see how we can give a new name for our existing image, We need to create a login account in https://hub.docker.com.
I have created a username as mahadev5
The docker images command will list down the images present in our docker machine
I will choose the image “ubuntu” and create a tag name for it as ubuntupushtodockerhub
command to do the above is – docker tag ubuntu:latest mahadev5/ubuntupushtodockerhub:latest
mahadev5 – is my dockerhub username and ubuntu is my image name
ubuntupushtodockerhub:latest – this is my new tag name
Let’s see how we can push images to the docker registry now
docker push mahadev5/ubuntupushtodockerhub
output :
Let’s see how we can pull an image from docker hub registry
docker pull alpine
Here alpine is the image name located in docker hub
Let’s see about docker Storage
Docker volume – this is mountable and used to store data in docker filesystem
Bind mounts – this mounts a volume of our host machine to the docker container
Please refer google for the commands and execute them in your host machine
Docker Network
It helps us to create a connectivity between docker container and outside world, the below snip shows available network in our docker machine
We create a network in docker using the command
docker network create “network name”
You can use the network we created for a container of your choice
Home work for you guys?
Practice everything, we discussed in this document in your host machine.
Explore more about docker storage, docker network, docker swarm, docker file, docker compose.
Happy Learning!!
(The word document I created earlier is replicated here)
Top comments (0)