# Day 17 Task: Docker Project for DevOps Engineers.

### ***<mark>Dockerfile:</mark>***

A Dockerfile is a text file used to define a set of instructions for building a Docker container image. The Docker container image contains an isolated environment with all the necessary dependencies, libraries, and application code to run a specific application.

`FROM`: This instruction specifies the base image for the container.

`WORKDIR`: Sets the working directory inside the container where the application code will be placed.

`COPY`: Copies the current directory contents (your application code) into the container's `/app` directory.

`RUN`: Executes the specified command inside the container during the image build process.

`ENV`: Sets an environment variable inside the container.

# **<mark>Task :</mark>**

### **<mark>Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)</mark>**

make a directory and Clone the repository in your system using the command git clone &lt;remote url&gt;

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690814601318/6e5df9a5-418a-4641-bc67-c4f779c5b902.png align="center")

***<mark>Create a Docker file.</mark>***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690814728010/646249bd-3666-41bf-8591-9d473de6c506.png align="center")

Docker file fields:

**<mark>FROM python:3.9</mark>**

It tells docker, which base image you want to base your image from. In our example, we are creating an image from the **Python** image.

**<mark>WORKDIR app</mark>**

As the name suggests, WORKDIR sets the directory that the container starts in. Its main purpose is to set the working directory for all future Dockerfile commands.

**<mark>COPY . /app</mark>**

copy your application code inside the docker image.

**RUN pip install -r requirement.txt**

The command is used for all dependencies in the requirement file.

**EXPOSE 8001**

commands used for release port 8001 within the container.

**CMD \["python","**[**manage.py**](http://manage.py)**","runserver","0.0.0.0:8001"\]**

The command starts the server and runs the application.

### **<mark>Build the image using the Dockerfile and run the container:</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690814934998/b36bda3f-e4ca-47da-af4d-296c30fd3143.png align="center")

<mark>docker images: We can see all docker images.</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690815221631/6553fdd7-0d0f-4ed8-8df1-424c1f6f5207.png align="center")

1. **<mark>Run the image to create a container:</mark>**
    

sudo docker run -d --name &lt;container\_name&gt; -p 8001:8001 &lt;image-name&gt;

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690815528534/1f9be871-e7ba-4ab7-a616-3138fe079bcd.png align="center")

**<mark>Verify that the application is working as expected by accessing it in a web browser:</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690815862733/7e0e42ce-ad0e-44ae-b736-84613ecf5e5b.png align="center")

* ### **<mark>Push the image to a public or private repository (e.g. Docker Hub )</mark>**
    
    *<mark>Create an account in Docker Hub.</mark>*
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690816191531/022db945-2c87-47aa-b869-f507a4e7c896.png align="center")
    

***<mark>login to docker and enter your username &amp; password of your docker hub</mark>***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690816869441/dd6302ac-2754-410a-a986-18ea19d9a8fd.png align="center")

*<mark>Check the docker images and Push that image to the docker hub using the </mark>* `docker push <image_name>` *<mark> command.</mark>*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690816994059/d8c6427d-285d-4e9b-a00e-3680835ff317.png align="center")

***<mark>Completed</mark>***.

Thanks for reading.
