Docker Hand Notes
Docker Hand Notes
Docker Hand Notes
applications.
➢ Docker uses container on the host OS to run applications. It allows applications to use same
Linux kernel as a system on the host computer rather than creating a whole virtual OS.
➢ We can install docker on any OS but docker engine runs natively on Linux distributions.
➢ Docker written in “GO” programming language.
➢ Docker is a tool that performs OS level virtualization also known as Containerization.
➢ Before docker many users face the problem that a particular code is running in the
developer’s system but not in the user’s system.
➢ Docker was first release in march 2013. It is developed by Solomon Hykes and Sebastian
Pahl.
➢ Docker is a set of Platform-as-a-Service that uses OS level virtualization whereas VMWare
uses hardware level of virtualization.
Advantages of Docker:
➢ No pre allocation of RAM.
➢ CI efficiency: - docker enables you to build a container image and use that same
image
across every step of the deployment process.
➢ Less cost.
➢ It is light in weight.
➢ It can run on physical h/w / virtual h/w or on cloud.
➢ You can reuse this image.
➢ It took very less time to create container.
Disadvantages of Docker:
➢ Docker is not a good solution for application that requires rich GUI.
➢ Difficult to manage large number of containers.
➢ Docker doesn’t provide cross platform compatibility means if an
application is designed to run in a docker container in windows than it can’t
run in Linux or vice-versa.
➢ Docker is suitable when the development O.S and testing O.S are same. If the
O.S are different then we should use VM.
➢ No solution for data recovery and backup.
Components of Docker:
A. Docker Daemon:
1. Docker daemon runs on host O.S.
2. It is responsible for running containers to manages docker
services.
3. Docker daemon can communicate with other daemons.
B. Docker Client:
1. Docker users can interact with docker through a client.
2. Docker client uses commands and REST API to communicate
with the docker daemon.
3. When a client runs any server command on the docker client
terminal, the client terminal sends these docker commands to
the docker daemon.
4. It is possible for docker client to communicate with more than
one daemon.
C. Docker Host:
1. Docker host is used to provide an environment to execute
and run applications.
2. It contains the docker daemon, images, containers, networks
and storages.
D.Docker Hub/ Registry:
➢ Docker registry manages and stores the docker image.
➢ There are two types of registries in the docker:
a. Public Registry: it is also called as docker hub.
b. Private Registry: it is used to share image with in the enterprise.
E. Docker Image:
1. Docker images are the read only binary templates used to
create docker containers.
or
Single file with all the dependencies and configuration required to run
a program.
Ways to Create an Image:
a. Take image from the docker hub.
b. Create image from docker file.
c. Create image from existing docker containers.
F. Docker Containers:
➢ Containers hold the entire packages that is needed to run the application.
Or
➢ In other words, we can say that the image is a template and the container is
a copy if that template.
➢ Container is like a virtual machine.
➢ Images becomes container when they run on docker engine.
To start container
#docker start container_name
To go inside container
# docker attach container_name
To stop container
# docker stop container_name
To delete a container
# docker rm container_name
Steps to create a image and container from existing image
and container
Step 1 create a container named deepak_centos with the help of centos image
docker run -it --name deepak_centos centos
Step 2: confirm the image is installed and container is created. (docker image and
docker ps -a)
Step 3: start the container and attach the container
Step4: now make changes in the centos like editing file/folder or installing apps.
Step5: verify the changes from base os and current one using docker diff command
Step6: commit the current os using below command
docker commit deepak_centos sidos
here sidos would be the updated image with required changes
step7 : Now create an updated container sidcontainer using updated os sidos
docker run -it --name sidcontainer sidos
Step8: to verify that sidcontainer has all the updated changes, start the sidcontainer and
then run ls command
Dockerfile is basically a text file. It contains some set of instructions. Automation of
docker image creation.
Dockerfile components:
FROM: for base image, this command must be on the top of the dockerfile.
RUN: to execute commands, it will create a layer in image
MAINTAINER: author/ owner/ description
COPY: copy files from local system (docker vm) we need to provide source, destination
(we can’t
download file from internet and any remote repo.)
ADD: similar to copy but it provides a feature to download files from internet, also
extract file at
docker image side.
EXPOSE: to expose ports such as port 8080 for tomcat , port 80 for nginx etc.
CMD: execute commands but during container creation.
ENTRYPOINT: similar to CMD but has higher priority over CMD, first commands will be
executed by ENTRYPOIN only.
ENV: environment variables
Docker Volume:
➢ Volume is simply a directory inside our container.
➢ Finally, we have to declare this directory as a volume and then share volume.
➢ Even if we stop the container still, we can access volume.
➢ Volume will be created in one container.
➢ You can declare a directory as a volume only while creating container.
➢ You can’t create volume from existing container.
➢ You can share one volume across any number of containers.
➢ Volume will not be included when you update an image.
➢ You can map volume in two ways:
a. Container to container
b. Host to container
Benefits of Volume:
➢ Decoupling container from storage.
➢ Share volume among different containers.
➢ Attach volume to containers.
➢ On deleting container volume doesn’t delete.
step 1
create volume using dockerfile like below
FROM ubuntu
VOLUME ["/myvolume1"]
Step2
Step3: