Day 17 : Docker Project for DevOps Engineers.

Day 17 : Docker Project for DevOps Engineers.

Here is a Docker Project configuring Dockerfile for SampleWebsite.

Project Link: https://github.com/Rohit312001/SampleWebsite

Today's challenge is a bit special Because we are going to do a DevOps project today with Docker.

Before moving to a project on Docker. Let's understand what is Dockerfile.

Dockerfile

  • A Dockerfile is like a set of instructions for making a container. It tells Docker what base image to use, what commands to run and what files to include.

  • For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.


The basic need for a Dockerfile is as follows:

  • Specify the base image (FROM): The first line of a Dockerfile should specify the base image that the Docker image will be built upon. This can be a minimal operating system image or a pre-built image that includes a specific software stack. {eg.FROM node}

  • Install dependencies (RUN): If your application has dependencies, you need to install them in the Docker image. This can be done using the RUN command in the Dockerfile.

  • Copy application files (COPY): After installing dependencies, you need to copy your application files into the Docker image. This can be done using the COPY command in the Dockerfile.

  • Set environment variables (ENV): You can set environment variables in the Dockerfile that will be used by your application. This can be done using the ENV command in the Dockerfile.

  • Expose ports (EXPOSE): If your application listens on a specific port, you need to expose that port in the Docker image. This can be done using the EXPOSE command in the Dockerfile.

  • Define the command to run (CMD): Finally, you need to specify the command that Docker will use to run your application inside the container. This can be done using the CMD command in the Dockerfile.


Tasks:

Create a Dockerfile for a simple web application.

Screenshot from 2023-03-30 02-33-29

Screenshot from 2023-03-30 02-35-12


Build the image using the Dockerfile and run the container.

Screenshot from 2023-03-30 02-33-46

Screenshot from 2023-03-30 02-34-25


Now run on the port you want to run your website.

Screenshot from 2023-03-30 02-34-46


Verify that the application is working as expected by accessing it in a web browser.

Screenshot from 2023-03-30 02-54-41


Push the image to a public or private repository (e.g. Docker Hub )

Screenshot from 2023-03-30 03-08-56

Screenshot from 2023-03-30 03-10-22


Happy Learning :)

Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!