Docker
Docker
CONTAINER : It is like a Virtual Machine and It does not have any OS.
VIRTUVALIZATION : process that allows for more efficient utilization of physical computer
hardware and is the foundation of cloud computing.
HYPERVISOR : Help to make virtualization and to create a VM
CONTAINARIZATION : Process of packing application along with its dependencies
DOCKER : It is a tool that create this Container. It is advance than Virtualization.
AM
AH
R
O.S LEVEL VIRTUALIZATION
It is an opensource centralized platform designed to create, deploy and run applications.
Docker is written on Go language.
Docker uses container on host O.S to run applications. It allows applications to use same
Linux kernel as a system on the host computer, rather than creating a whole virtual O.S.
We can install Docker on any O.S but docker engine runs natively on Linux distribution.
Docker performs O.S level Virtualization also known as Containerization.
Before Docker many user face problems that a particular code is running in the developer’s
system but not in the user system.
It was initially release in March 2013, and developed by Solomon hykes and Sebastian pahl.
Docker is a set of platform-as-a-service that use O.S level Virtualization, where as VM ware
uses Hardware level Virtualization.
Container consists O.S files but its negligible in size compared to original files of that O.S.
ARCHITECTURE
AM
AH
R
DOCKER CLIENT: is the primary way that many Docker users interact with Docker.
When you use commands such as docker run, the client sends these commands
to docker daemon, which carries them out. The docker command uses
the Docker API.
DOCKER HOST: Docker host is the machine where you installed the docker engine
AM
: docker stop container name
: docker rm container name
DOCKER FILE
It is basically a text file which contains some set of instructions.
Automation of Docker image creation.
Always D is capital letter on Docker file.
And Start Components also be Capital letter.
DOCKER FILE COMPONENTS
FROM: For base image this command must be on top of the file.
RUN: To execute commands, it will create a layer in file.
COPY: Copy files from local system (docker VM) where need to provide Source and Destination.
ADD: It can download files from internet and also, we can extract file at docker image side.
EXPOSE: To expose ports such as 8080 for tomcat and port 80 nginx etc.
WORKDIR: To set working directory for the Container.
CMD: Executes commands but during Container creation.
ENTRYPOINT: High priority than CMD, because first command will be executed by Entry point only.
ENV: Environment Variables.
ARG: Defines a variable that can be used to build a Docker image
Difference b/w Copy and Add is in copy we can’t download file from internet and any remote repo.
FILE CREATION
Create a file called Docker file and Add instructions in Docker file.
Build Docker file to create image.
Run image to Create Container.
Vi Docker file
FROM ubuntu
RUN echo “Hello world!” > /tmp/testfile
To create image out of Docker file
AM
docker build -t image-name . (. = current directory)
docker ps -a and docker images.
AH
Now create container from the above image.
docker run -it - -name container-name image-name /bin/bash
Cat /tmp/testfile
R
Give docker run -it - -name container name image-name /bin/bash
DOCKER VOLUMES
When we create a Container then Volume will be created.
Volume is simply a directory inside our container.
First, we have to declare the directory Volume and then share Volume.
Even if we stop the container still, we can access the volume.
Volume will be created in one Container.
AM
You can declare directory as a volume only while creating container.
We can’t create volume from existing container.
You can share one volume across many number of Containers.
Volume will not be included when you update an image.
If Container-1 volume is shared to Container-2 the changes made by Container-2 will be also
available in the Container-1.
You can map Volume in two ways
AH
1. Container < ------ > Container
2. Host < ------- > Container
USES OF VOLUMES
Decoupling Container from storage.
Share Volume among different Containers.
R
DOCKER PUSH
R
Select an image which include docker and S.G SSH and HTTP enable anywhere on it.
docker run -it ubuntu /bin/bash
Create some filed inside container and create image from that container by using
docker commit container-name image1
now create docker hub account
Go to Ec2 and login by using docker login.
Enter username and password.
Now give tag to your image, without tagging we can’t push our image to docker.
docker tag image1 rahamshaik/new-image-name (ex: project1)
docker push rahamshaik/project1
Now you can see this image in docker hub account.
Now create one instance in another region and pull image from hub.
docker pull rahamshaik/project1
docker run -it - -name mycontainer rahamshaik/project1 /bin/bash
Now give ls and cd tmp and ls you can see the files you created.
Now go to docker hub and select your image -- > settings -- > make it private.
Now run docker pull rahamshaik/project1
If it denied then login again and run it.
If you want to delete image settings -- > project1 -- > delete.
AM
AH
R