#90DAYSOFDEVOPSCHALLENGE

Day 17 : Docker Project for DevOps Engineers.

Abhay Vishwakarma
4 min readJan 27, 2023

• Dockerfile :

Dockerfile is a simple text file that consists a set of instructions to build Docker images. A Dockerfile that contains commands that are used to assemble an image. We can use any command that call on the command line. Docker builds images automatically by reading the instructions from the Dockerfile. The docker build command is used to build an image from the Dockerfile. Docker runs instructions of Dockerfile in top to bottom order. The first instruction must be FROM in order to specify the Base Image.

· Here, we are listing some commonly used instructions.

FROM : This instruction is used to set the Base Image for the subsequent instructions. A valid Dockerfile must have FROM as its first instruction.

Ex. FROM ubuntu

LABEL : We can add labels to an image to organize images of our project. We need to use LABEL instruction to set label for the image.

Ex. LABEL vendorl = “JavaTpoint”

RUN : This instruction is used to execute any command of the current image.

Ex. RUN /bin/bash -c ‘source $HOME/.bashrc; echo $HOME’

CMD : This is used to execute application by the image. We should use CMD always in the following form

1. CMD [“executable”, “param1”, “param2”?]

This is preferred way to use CMD. There can be only one CMD in a Dockerfile. If we use more than one CMD, only last one will execute.

COPY : This instruction is used to copy new files or directories from source to the filesystem of the container at the destination.

Ex. COPY abc/ /xyz

WORKDIR : The WORKDIR is used to set the working directory for any RUN, CMD and COPY instruction that follows it in the Dockerfile. If work directory does not exist, it will be created by default.

  1. WORKDIR /var/www/html

Tasks :

1)Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)

a) First we build a simple web application on python as “app-master” & then use it to create a docker file.

b) To create a Dockerfile for python app, create a file named “Dockerfile”.

c) Here to view the Dockerfile & add a Script to it.

2) Build the image using the Dockerfile and run the container.

a) Build the dockerfile using command “sudo docker build . -t app-master”.

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

To verify that the application is working, you can access it in a web browser by going to “http://localhost:8000".

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

Use command “docker login” to login to dockerhub. Then use the command “sudo docker tag <image_name>:tag username/image_name”.

At last, perform the command “sudo docker push docker_hub_user-id/<image_name”>

Thank you for reading this blog. I hope you find this really interesting.

If you like it then press ‘Clap’ button and Follow me on Linkedin & Github platform.

— Abhay Vishwakarma

--

--