Sometimes a code does work on the developer system, but the same code does not work in the testing environment.
Docker resolves this issue of application working on one platform, does not work on some other platform.
Docker work on 3rd stage
An application needs various stacks, components and dependencies, these things take a lot time that whether an application will work or deploy on different — different platforms or not, for resolve this issue ,docker container is used.
— Docker makes the process of application deployment very easy and efficient and resolves a lot of issues related to deploying applications.
— Docker is the world’s leading software contained platform.
— Docker is a tool designed to make it easier to deploy and run applications by using containers.
— Contained allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
— Developer will package all the software and its components into the box and docker will take care of shipping the container to all the possible platforms in a standard way. In this way, we can resolve issues about on the application work on one environment not work on another environment.
Workflow of Docker :
In a docker workflow, docker will define all the applications and their dependencies and requirement In a file, that is called docker file, this docker file can be used to create docker images.
A docker image has all applications, requirements and dependencies, and when we run docker Image we get docker containers, docker containers is a run time instance of Docker image, and these images can be stored in Online cloud repository that is called docker hub, If we go. inside the docker hub, we find online public images or we can store their own images.
These docker images can be pulled in any environment (test environment or staging environment) and our application will be run in the same way in docker containers.
— Docker has client-server architecture.
— Docker server receives the commands from the docker client through CLI or Rest API’s.
— Docker client and server can be present on the same host (machine) or different hosts.
Benefits of using docker :
— It solves the problem of code working on one system and not working on other System.
— An application inside a container can run on any system that has docker installed. So there is no need to build and configure app multiple times on different platforms.
— Here we can create a docker image, which we can put on docker image in docker hub Or any online repository, and we can run this image in any environment and run the Image to create a docker container and our application will run inside the container. We can do the same with the production environment.
— With Docker, we test our application inside a container and ship it inside a container This means the environment in which we test is identical to the one on which the app will Run in production.
— Docker containers can run on any platform.
— It can run on our local system Amazon ec2, GCP, VirtualBox…etc.
— Docker containers work just like GIT repositories allowing you to commit changes to your Images and version control them.
— In Docker, every application works in isolation in its own container and does not interfere with other applications running on the same system.
So multiple containers can run on the same system without interference.For removal also we can simply delete the container and it will not leave behind any file or trace on the system.
— Docker allows faster and more efficient deployments without worrying about running your app on different platforms. It will increase productivity.
Some basics commands
o docker images > list out all the images
o docker ps > list out all the running containers
o docker ps -a > list out all the containers
o docker run “image-name” > it will run image “image-name”
o sudo service docker stop > for stop the docker
o docker version
o docker -v
o docker info
o docker — help
o docker login
o docker ps > list all the containers
o docker run “image_name” > used for run Docker containers
o docker run -it “docker container” > if We want to start the docker container
o docker start “container id”
o docker stop “container id”
o docker stats > this gives us the details about running containers, memory usages and i/o
o docker system df > disk usage of docker (images, container and local volumes size)
o docker system prune > it is used to remove unused data
o docker system prune -a > remove all unused images not just dangling ones (dangling images: images that are not associated with running containers ), it will not remove running containers
What are the docker images :
Images are the template used to create docker containers, containers are running instance of image.
So basically images are the files that tell us, which things are necessary to create docker containers When we run the image, the container is created.
Some commands
o Docker images — help
o Docker pull image
o Docker images
o docker pull “image_name” > use to pull images
o docker -q > (only give the docker images id)
o docker images -a > (give all the details + id)
o docker rmi “image id” >it is used to remove images
o Docker images -f “dangling=false” > will give the images for that dangling = false(dangling images : images
that is associated with running containers)
o Docker inspect “image name”: give the complete info about images (hostname, layers, id…)
o Docker rmi “image name” >we will stop the associate container with image
o Docker rmi -f “image name” >(forcefully remove)
What are the docker containers :
Containers are running instances of docker images
o docker pull goes to the local online registry (docker hub), pull the image from there and save the image into our local system of localhost.
o docker run check the images in the local system if it is available it will create docker container from that image, and if Image is not available it will just pull the image from the local registry.
o docker build is used to create docker image using docker images and then create a container.
Some commands :
— docker run — name “container-name” -it “image-name” ( >it will run the container and and container name is MyUbuntu1)
— docker pause containerName/id
— docker unpause containerName/id
— docker top containerName/id (> show the top processes of the container)
— docker stats containerName/id (>it will give stats like memory usage, i/o..etc)
— docker attach containerName/id (>it will attach to the running container)
— docker rm containerName/id (> for remove the particular container)
— docker kill containerName/id
— docker history containerName/id
What are the docker Files:
A text file with instructions to build image automation of docker image creation if we want to create our own image file, we will use docker files.
STEPS FOR CREATE DOCKER IMAGE
## Step1 : Create a file name Dockerfile
kapil@asr04:~$ mkdir DockerFiles
kapil@asr04:~$ touch ./DockerFiles/Dockerfile
kapil@asr04:~$ vim ./dockerFiles/Dockerfile
## Step2 : Add instruction in Dockerfile
~ # getting base image
~From ubuntu
~MAINTAINER kapil <kapil16garg.gmail.com>
~RUN aot-grt update
~CMD [“echo”, ‘Hello world…| from my firsr docker image”}
~
________________________________________________________
## Step3 : Build dockerfile to create image
kapil@asr04:~$ docker build -t myimage1:1.0 ./DockerFiles ##give the name of image
## Step4 : Run image to create container