Monday, January 10, 2022

Docker Components Overview


What Is Docker ?

  • Docker is a platform for developing, shipping, and running applications in a form of containers, Containers provide a lightweight and consistent environment to bundle their own software, libraries and configuration.

What is Docker File ?

  • A Dockerfile basically a text file that contains a set of instructions and commands used to assemble an image.

What is Docker Compose ?

  • Docker Compose is a tool, that allow you to define and manage multi-container Docker applications using a YAML file and in YAML file you can define the services, their dependencies, networks, volumes, and other configurations.

What is Docker-compose.yml File ?

  • A docker-compose.yml is a config file for docker-compose, it allows to deploy, combine and configure multiple docker-container at the same time.

What are the Docker images ?

  • Docker images are read-only templates that contains application code, libraries, dependencies, tools, and other files required for an application to run.

What is Docker Container ?

  • Docker containers are runtime instances of Docker images, They encapsulate an application along with its dependencies and run in isolated user spaces on the host operating system.

What is Docker Hub ?

  • Docker Hub is a cloud-based repository for Docker images. It's a centralized platform where developers and organizations can store, share, and manage Docker images.

What Is Docker Volume ? 

  • Docker volumes are file systems mounted on Docker containers to preserve data generated by the running container.
  • Volumes: Volumes are stored in a part of the host filesystem, managed by Docker (/var/lib/docker/volumes/ on Linux).



What are the Docker file key components or instructions

  • FROM    : The FROM instruction define the docker base image.
  • WORKDIR : The WORKDIR instruction define the working directory inside the container where subsequent commands are executed.
  • COPY    : The COPY instruction is responsible for copy files from the host machine to the container's filesystem.
  • ADD    : The ADD instruction has similer to COPY but it has more ability like:- download the files from internet via URLs and automatically unpacks archive files inside the container.
  • RUN    : The RUN instruction executes commands within the container during the image build process. It's used to install dependencies and configure the environment.
  • EXPOSE    : The EXPOSE instruction define the ports from the container to the host machine for enabling the communication.
  • CMD    : The CMD instruction is a default command in a Docker container, that will be executed when a Docker container starts and it can be override.
  • Entrypoint: The Entrypoint instruction is a primary command in a Docker container, that will be executed when a Docker container starts, and The Entrypoint instruction append the values rather than replacing or overriding them.
  • USER    : The USER instruction set the UID that the container should run as, enhancing security by limiting privileges.
  • ENV    : The ENV instruction is used to set the environment variables that is required to run the project. (Example ENV : HTTP_PORT="9000")
  • LABEL    : The LABEL instruction is used to add metadata to an image. It provides additional information about the image, and author making it easier to manage and identify.



What is difference between CMD and ENTRYPOINT command.

  • The CMD instruction can be override by passing the parameters from the docker run CLI command but The Entrypoint instruction append the values rather than replacing or overriding them.


Example : Let’s take a npm init example for node.

------------------------------------------------------------------------------------
CMD : Let’s assume below is the initial command we added in Dockerfile.
CMD [ "npm", "init" ]
Now, If I run docker run -t node npm install
It will override the npm init command from the dockerfile.
CMD [ "npm", "init" ] This will become  CMD [ "npm", "install" ]
It will execute the npm install command rather than npm init as it overrides with npm install.
------------------------------------------------------------------------------------

ENTRYPOINT : Let’s assume the same command is added in docker file but with ENTRYPOINT
ENTRYPOINT [ "npm", "init" ]
Now, If I run docker run -t node install
It will append the npm init command with npm install in the dockerfile.
ENTRYPOINT [ "npm", "init" ] This will become  ENTRYPOINT [ "npm", "init", "install" ]
It will execute the both npm init & npm install commands.
------------------------------------------------------------------------------------

No comments:

Post a Comment

testing