Docker concepts with execution in Server
Published: 2022-08-06 02:51:50


**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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kou2t1qblksepbdwcx7a.png)
 
 

**Steps involved to install Docker**

1.	sudo apt-get update
2.	sudo apt-get upgrade
3.	sudo apt-get install \ca-certificates \curl \gnupg \lsb-release - this command is to allow apt to use a repository over HTTPS
4.	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 repository

5.	sudo 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

6.	sudo apt-cache policy docker-ce   -> this command is to add docker repo

output -  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3351zaej9m299jr5tpwv.png)
 

7.	sudo systemctl status docker  to check the status of docker
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8zggvebr6cli8918e6d.png)
 
 
8.	sudo apt-get upgrade 
9.	sudo service docker start
10.	 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 sudo

11.   **docker 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 Docker
1.	**Docker 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 Registry
2.	**Docker Registry** -> It can be an OS image or an application image such as nodejs,php
3.	**Docker client** - > docker build, run, pull, push
4.	**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 container 
1.	**docker 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)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukwvigj3clpfndmi0zeb.png)
 
2.	**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
3.	docker ps –a
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/901s16g0rl04lfsoej5x.png)
 






4. 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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdljb4xvpbidnv1bbmix.png)
 

 
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
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd5ovxf6p00zwmn1xmzz.png)
 
 

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 - 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbrodmc3obrejslwzm4z.png)
 
 
The command to list out the number of images in our docker machine is
docker images 
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yl24tyl2odabzk6l1opn.png)
 
The command to remove an image available in docker machine is
Docker rmi imagename –force       docker rmi hello-world –force
Output -
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbqlazvk0cyxmxp9n5qa.png)
 







The command to check images available in dockerhub for a particular OS or application
docker search image name or applicationnanme
docker search php

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ol3s4a1vz0lwgua3ba86.png)
 
 
The command to stop a running container is 
docker stop containerid 
docker stop 5258ae771fba
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnpf5edqrm7ei64ghvr4.png)
 
 
The command to start a container 
docker start 5258ae771fba

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b6s6cj9hx01r61joomy.png)
 
 

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
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/be0okdx74yewdpmcalhu.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5demznlw3m72alqi91yh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh5ab6yzmdbcunheyo9t.png)
   

 
 






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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgvl0kcw8md94lt64814.png)
 
 
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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uc6ajakipvvpwpgq6v6v.png)
 
 
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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpj5ej50w8sjyor3vxwm.png)
 
 

Let’s see how we can push images to the docker registry now
docker push mahadev5/ubuntupushtodockerhub
output :
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkqym0ty51rvw75qkwe2.png)
 







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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0bucnj74fib8kol93vt.png)
 
 

Let’s see about docker Storage 
1.	Docker volume – this is mountable and used to store data in docker filesystem

2.	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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/779qegmv14c5ugpsrgkb.png)
 

 
We create a network in docker using the command 
docker network create “network name”

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hp2zq5gn93yaxea6n3rj.png)
 
 
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)