Learning of Docker concepts
Docker is a container management service. The keywords of Docker are develop, ship and run anywhere. The whole idea of Docker is for developers to easily develop applications, ship them into containers which can then be deployed anywhere.Docker is container based technology and containers are just user space of the operating system.In Docker, the containers running share the host OS kernel.
When we can use Docker?
Docker is a basic tool, like git or java, that you should start incorporating into your daily development and ops practices.
Features of Docker:
Main Components of Docker:
High level Architecture of Docker:
Docker Toolbox:
The Docker Toolbox is an installer to quickly and easily install and setup a Docker environment on your computer. Available for both Windows and Mac.
You can download Docker ToolBox from − https://www.docker.com/products/docker-toolbox
I have downloaded the Windows version of Docker (DockerToolbox-19.03.1.exe) to practice all the commands.
Docker image & Docker container:
In Docker, everything is based on Images. An image is a combination of a file system and parameters. A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container. An image is essentially built from the instructions for a complete and executable version of an application, which relies on the host OS kernel.
Docker Container is the instantiation of Docker Image. In other words, Docker Container is the run time instance of images.Containers are instances of Docker images that can be run using the Docker run command. The basic purpose of Docker is to run containers.
Let’s take an example of the following command in Docker.
When we can use Docker?
Docker is a basic tool, like git or java, that you should start incorporating into your daily development and ops practices.
- Use Docker as version control system for your entire app's operating system
- Use Docker when you want to distribute/collaborate on your app's operating system with a team
- Use Docker to run your code on your laptop in the same environment as you have on your server
- Use Docker whenever your app needs to go through multiple phases of development (dev/test/qa/prod)
Features of Docker:
- Docker has the ability to reduce the size of development by providing a smaller footprint of the operating system via containers.
- With containers, it becomes easier for teams across different units, such as development, QA and Operations to work seamlessly across applications.
- We can deploy Docker containers anywhere, on any physical and virtual machines and even on the cloud.
- Since Docker containers are pretty lightweight, they are very easily scalable.
Main Components of Docker:
- Docker for Mac/Windows/Linux - It allows one to run Docker containers on any OS
- Docker Engine − It is used for building Docker images and creating Docker containers.
- Docker Hub − This is the registry which is used to host various Docker images.
- Docker Compose − This is used to define applications using multiple Docker containers.
High level Architecture of Docker:
Docker Toolbox:
The Docker Toolbox is an installer to quickly and easily install and setup a Docker environment on your computer. Available for both Windows and Mac.
You can download Docker ToolBox from − https://www.docker.com/products/docker-toolbox
I have downloaded the Windows version of Docker (DockerToolbox-19.03.1.exe) to practice all the commands.
Docker Hub:
Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub.
The official site for Docker hub is − https://www.docker.com/community-edition#/add_ons
In Docker, everything is based on Images. An image is a combination of a file system and parameters. A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container. An image is essentially built from the instructions for a complete and executable version of an application, which relies on the host OS kernel.
Docker Container is the instantiation of Docker Image. In other words, Docker Container is the run time instance of images.Containers are instances of Docker images that can be run using the Docker run command. The basic purpose of Docker is to run containers.
Let’s take an example of the following command in Docker.
docker run hello-world
- The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.
- The run command is used to mention that we want to create an instance of an image, which is then called a container.
- Finally, "hello-world" represents the image from which the container is made.
Create our Docker image and Push it to Docker Hub:
Docker gives us the capability to create your own Docker images, and it can be done with the help of Docker Files. A Docker File is a simple text file with instructions on what we need to deploy.
Example to create a sample docker image from local host and push it to the public repository:
Step1: Create a sample Dockerfile with the name "Dockerfile" with the below content in a directory/folder called "Test" from our system (Windows)
#This is a sample Dockerfile
FROM ubuntu
CMD [“echo”,”Hello World!!”]
Step2: Run the command to build the image using command => docker build -t testdocker:1.0 Test (sample Docker image id:babd6c938045)
Step3: Now we need to upload/push the above image to public repository with the below steps
a) Go to https://hub.docker.com and select "Create Repository" (Eg:sampledocker).
b) After that, we need to login into Dockerhub site from system using command => docker login and then give username/pwd.
c) After that,we need to tag the above image id to the public repository by using command => docker tag babd6c938045 urspvs/sampledocker:1.0
d) After that, we need to push the "testdocker" image to the public repository using the command => docker push urspvs/sampledocker:1.0
Step4: To pull the public reposiroty image created from the above process is like => docker pull urspvs/sampledocker:1.0
Useful Docker Commands Run From Toolbox (Windows):
- docker --version
- docker images == List of Docker images
- docker ps -a === List of containers/processes
- docker rm --force
== Remove a container - docker rmi -f
== Remove a specified Docker image - docker run hello-world == Run the default Docker image from Docker hub if it is not in the system
- docker rm $(docker ps -a -q) == Remove all containers
- docker rmi $(docker images -q) == Remove all images
- docker commit
== create a new container for DB - docker build -t
. == build the Docker image - docker build -t ImageName:TagName dir (Eg: docker build -t testdocker:1.0 Test)
- ./install.bat == run the batch file
- docker container stop
- docker container start
- docker container rm
- docker pull jenkins == Pull Jenkins and load in the local Docker
- docker pull mcr.microsoft.com/windows/servercore/iis (to pull IIS image from Docker Hub)
- docker run -p 8080:8080 -p 50000:50000 jenkins == To run the Jenkins successfully as a container
- docker inspect
== see the details of an image or container - docker history
== Show all the commands that were run against the image - docker stats
== Show the CPU and Memory utilization of the Container - docker kill
== used to kill the processes in a running container
References:
2) https://www.google.com/
3) https://www.tutorialspoint.com/
3) https://www.tutorialspoint.com/

