How To Dockerize An Application- Part II

Photo by Ian Taylor on Unsplash

How To Dockerize An Application- Part II

What is Dockerize?

Dockerizing is the process of packing, deploying, and running applications using Docker containers.

Chose a base image

You can start from a Base OS and install everything by yourself. Choose an image based on the used technology, such as Node, Java, Ruby, and Python. I am going to use Node for my hello-world application.

  • 1. Create a file hello-world.js

      Console.log("Hello World");
    
  • 2. Create a Dockerfile in the root directory with the same name Dockerfile and write the following instructions

      FROM node:alpine
      COPY ./app
      WORKDIR /app
      CMD node app.js
    
    • 3. Build the Docker image from this Dockerfile, you can run the following command from the directory containing the Dockerfile. This will create a Docker image with the tag `hello-world`

        docker build -t hello-world .
      
      • 4. Finally, you can run the Docker container from the image using the following command

          docker run hello-world