Docker is also known as containerization. Docker is the advanced version of virtualization. Docker is an open platform for developing, shipping and running applications. It is used to deploy the code quickly. It is the concept of containerization that enables you to separate your application from your infrastructure. Docker is mainly used to free from the hassle. Although docker uses a similar concept of a virtual machine it is not a virtual machine. It is written in go language.

We can use the docker to push our application into a test environment and execute it automatically. When we use Docker, we create and use images, containers, networks, volumes, plugins, and other objects.

[Note:- when we say Docker we are talking about the entire ecosystem of Docker products like it includes Docker client, Docker server, Docker machine, Docker hub, Docker compose etc.]

Docker Client & Docker Server

Docker client is a tool we issue commands to for reaching out to docker daemon(server).

The Docker daemon is a service that runs on your hosting operating system. It is responsible for running containers.

Image & Container

An image is a single file with all the dependencies and configurations to run a program.

The container has an isolated set of hardware resources that run inside our machine and occupy the space inside the machine.

Docker (image)

you might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile.

Docker Commands

  1. docker search Jenkins, ubuntu, etc == to find the image in docker hub

  2. docker pull jenkins == pulling an image from docker hub

  3. docker run -it --name itsjenkins(image name) chef /bin/bash == pull the image and run at the same time.

  4. exit == exit from container.

  5. docker images == see image available in docker

  6. docker ps == shows all running containers

  7. docker ps -a == shows all the running and stop container

  8. docker start [name of stop container which we want to resume again].

  9. docker attach [running container name] ===== to go inside the container and start our work.

  10. docker stop [container name] ===== stop running container

  11. docker rm [container name] ==== remove container [[[[[Note ::: we can only remove or delete stop container not running one]]]]]]]]]

  12. docker container prune —— remove all stop container

  13. docker rmi (docker image name or image id) ——— to remove the docker image

  14. docker rmi -f (docker image name or image id) —— to remove the docker image forcefully.

Creating Image From Existing Container

  1. docker commit itsjenkins(existing container name) jenkinsimg(image name) === docker image creating

  2. docker run -it —name itsjenkins1 (container name) jenkinsimg (image name) /bin/bash ===== new container from jenkinsimg which is created by us.

Dockerfile

A Dockerfile is basically a text file that contains some set of instructions. Automation of docker image creation.

  1. FROM——— for the base image, this command must be on top of the dockerfile.

  2. RUN echo ————- To execute the command, it will create a layer in the image

  3. MAINTAINER ——————— Author/owner/description

  4. COPY ———————- copy files from the local system (docker vm) we need to provide sources, and destinations (we can download files from the internet and any remote repo)

  5. ADD —————- Similar to copy but, it provides a feature to download files from the internet, also we extract files at the docker image side

  6. EXPOSE——————To expose ports such as port 8080 for Tomcat, port 80 for nginx etc

  7. WORKDIR ———————— To set a working directory for a container

  8. CMD ————— Execute command but during container creation

  9. ENTRYPOINT ————-similar to CMD, but has higher priority over CMD, first commands will be executed by ENTRYPOINT only

  10. ENV —————————- Environment variables