Docker
Docker is a container platform that allows you to build, test and deploy applications quickly. A developer defines all the application and its dependencies in a Dockerfile which is used to build Docker images that define containers
why use Docker
Using Docker can help you ship your Code faster and give you control over your application. You can deploy applications on containers that make it easier for them to be deployed, scaled, perform rollbacks and identify issues. you can use Docker for microservices, Data processing, Continuous Integration, and Delivery container as a service.
Docker Architecture
Docker users a client-server architecture. The Docker Client talks to the Docker daemon. which does the heavy lifting of building, running, and distributing your Docker containers Dockerfile, Docker Images, and Docker Containers one the three important terms that you need to understand while using Docker
As you can see in the above diagram when the Dockerfile is built, it becomes a docker Image and when we run the Docker Image then it finally becomes a Docker container
Docker file
A Dockerfile is a text document that contains all the commands the user can call on the Command line to assemble an image. so Docker can build Images automatically by reading the instructors from a Dockerfile. you can use docker build to create an automated build to execute several command-Line instructions in succession
The following command shows some of the docker file Statements we will be using or that you will likely be using.
FROM:- To specify the parent image
WORKDIR:- To set the working directory for any command, that follows in the Dockafile.
RUN:- To install any application and package required for your containers
COPY:- To copy over a file or directory from a specific location.
ADD:- AS COPY but also able to handle remote URLs and Unpack compressed files.
Entry point:- command that will always be executed when the container start. if not specified, the default is bin/sh-C
CMD:- Argument passed to the entry point. If the entry point is not set ( default to bin/sh-s ) the CMD will be the commands the container executes
EXPOSE:- to define which port through which to access your container application.
LABEL:- To add metadata to the image
Step:- 1 Write the docker instruction or commands in the docker file that need to be executed.
# Use the official Ubuntu 18.04 as base
FROM ubuntu:18.04
# Install nginx and curl
RUN apt-get update && apt-get upgrade -y
#RUN apt-get install -y nginx curl
#RUN rm -rf /var/lib/apt/lists/
RUN groupadd -g 1000 basicuser && useradd -r -u 1000 -g basicuser basicuser
USER basicuser
This is a docker file. You can save this file with the name dockerfile
.Please check that the file Dockerfile has no file extension like .txt
. Some editors may append this file extension automatically and this would result in an error in the next step.
What are Images
A container image is a lightweight, Standalone, executable package of software that includes everything needed to run an application's code, runtime, system tools, system libraries, and settings, container image becomes containers runtime.
In layman's terms, Docker Image can be compared to the template which is used to create a docker container. So there read-only template is the building block of a container you can use docker run
to run the image and create a container.
Step:- 2 Now open a terminal and go to the directory where the Dockerfile is stored. Now build the container image using the docker build command.
docker build -t getting-started
This command used the Dockerfile to build a new container image.
the -t
flag tags our image. Think of this simply as a human-readable name for the final image. Since we named the image getting-started, we can refer to that image when we run a container.
The .
at the end of the docker build command tells Docker that it should look for the Dockerfile in the current directory.
Docker Container
it is a running instance of a Docker Image as. they hold the entire package needed to run the application. So, these are basically the ready application created from docker Images which is the ultimate utility of docker
Step:- 2* Now that we have an image, let’s run the application. To do so, we will use the docker run
command. Start your container using the docker run
command and specify the name of the image we just created
docker run getting-started
Great, you have created your own container.
Basic Commands
docker ps #List all containers
docker run <ImageName / ID> #checks locally for Image if not it will pull
docker start <Container Name / ID> #start the container
docker Kill <Container Norme/ID> #Stor a running container
docker rm <Container Name /ID> #Deletes a stopped container
Docker Daemon
it listens to the API requests being made through the Docker client and manages Docker objects such as images, containers, networks, and volumes.
Docker Client
This is what you use to interact with Docker. when you run a command using docker, the Client sends the command to the daemon which carries them out. The Docker client can Communicate with more than one daemon
Docker registries.
This is where Docker images one stored. Docker Hub is a public registry that anyone can use. when you pull an image, by Docker default looks for it in the public registry and saves the image on your local system on DOCKER HOST You can also store images on Your local machine or push them to the Public Registry
Thank You for reading if you liked it then please share it with your friend and follow me on Twitter.