Understanding Commonly used DockerFile statements

 In this Exercise we will understand the use of commonly referred commands in Docker file for containerizing a Node js application. Lets take an example of a docker file as given below:

Docker File Keywords

Docker File

  • FROM <Image Name>:<Image Version>

      This represents the base image to be used for the container, this depends on the type of application we are containerizing in this case its node because we are trying to containerize Node application.

  • ENV <Environment Identifier> = <Environment Name>

     This statement sets the Environment needed for running the application.

  • WORKDIR <Working directory name>
     This identifies the directory which will be used within the container image for running the application.

  • COPY <List of files>
    This allows us to copy the required files which is necessary to setup the environment  and install the required dependency before starting the application. In this case we are copying the package.json file which contains the dependencies needed to start the application.

  • RUN <Command>
    This statement is used to run any command in the container working directory which is required to setup the environment and install the dependency, in our case its to install the dependencies specified in the package.json.

  •  EXPOSE <port number>
  This statement is used to expose the port number used by the application in the container. so that external world can communicate with the application.

  • USER <user name>
  This statement is used to define the user which will be used for running the application. Default user will be the user of the parent or the base image.

  • CMD <Command>
  This statement is used to start the application which is being containerized, This statement gets executed while the container starts. Unlike the RUN command which gets executed inside the docker image while the daemon tries to build the Docker image. In our case its node <start file name> since its a Node js application server.

Suggested Read : Containerizing Application using Docker








Comments

Popular posts from this blog

Creating RESTful Minimal WebAPI in .Net 6 in an Easy Manner! | FastEndpoints

Mastering Concurrency with Latches and Barriers in C++20: A Practical Guide for Students

Graph Visualization using MSAGL with Examples