# Day 17 Task: Docker Project for DevOps Engineers.

## DockerFile:-

Docker can build images automatically by reading the instructions from a `Dockerfile`. A `Dockerfile` is a text document that contains all the commands a user could call on the command line to assemble an image. This page describes the commands you can use in a `Dockerfile.`

## **Format**

Here is the format of the `Dockerfile`

```plaintext
# Comment
INSTRUCTION arguments
```

The instruction is not case-sensitive. However, the convention is for them to be UPPERCASE to distinguish them from arguments more easily.

Docker runs instructions in a `Dockerfile` in order. A `Dockerfile` **must begin with a** `FROM` instruction. This may be after [parser directives](https://docs.docker.com/engine/reference/builder/#parser-directives), [comments](https://docs.docker.com/engine/reference/builder/#format), and globally scoped [ARGs](https://docs.docker.com/engine/reference/builder/#arg). The `FROM` instruction specifies the [*Parent Image*](https://docs.docker.com/glossary/#parent-image) from which you are building. `FROM` may only be preceded by one or more `ARG` instructions, which declare arguments that are used in `FROM` lines in the `Dockerfile`.

Docker treats lines that *begin* with `#` as a comment unless the line is a valid [parser directive](https://docs.docker.com/engine/reference/builder/#parser-directives). A `#` marker anywhere else in a line is treated as an argument. This allows statements like:

```plaintext
# Comment
RUN echo 'we are running some # of cool things'
```

**Dockerfile instruction**

* **FROM** &gt; Base Image
    
* **ADD/COPY** &gt; Add files and folder into the image
    
* **RUN** &gt; Execute commands in a new layer and commit the results.
    
* **EXPOSE**&gt; Containers listen on the specified network ports at runtime.
    
* **CMD** &gt; Run binaries /commands on docker run
    

## Task:-

* Create a Dockerfile for a simple web application ( Python app)
    
* Build the image using the Dockerfile and run the container
    
* Verify that the application is working as expected by accessing it in a web browser
    
* Push the image to a public or private repository (e.g. Docker Hub )
    

Follow the Steps:-

1. Clone the GitHub repository from where you will get your required files.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683116641674/254cd862-2630-47c6-9ff1-87cb8f75c80c.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683116746814/33fe413b-c8b8-4ae1-8230-a3e0080a8cda.png align="center")
    
2. remove the previous Dockerfile.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683116838445/493d9df1-9cad-47db-adec-e105f1cc8bd0.png align="center")
    
3. ***vim DockerFile*** add the below content in it
    
    1. ```plaintext
         vim Dockerfile
         
          # Dockerfile content
          FROM python:3.9
          COPY . .
          RUN pip install -r requirements.txt 
          EXPOSE 8001
          CMD ["python","manage.py","runserver","0.0.0.0:8001"]
        ```
        
        To Build the image from Dockerfile.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683281131597/f5cb9ec1-4faf-4bdc-bac3-1b4b609ce68c.png align="center")
        
        Run the image to create the container.
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683117686387/aabcdef8-22a6-4a2d-b84d-5ea4617efe44.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683117274311/2385c36c-a4f3-47a1-a833-fdd8c776c9bf.png align="center")

1. Verify application is working in a web browser.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683120330901/fac9059c-7168-4fc7-9595-2b0d2ef25752.png align="center")
    
    Push the image to a public or private repository. (eg. dockerhub)
    
    create a docker hub account
    
    create a docker hub public repository
    
    change local image tag according to the docker hub suggest
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683120670974/3cdadc31-7c1c-4ed9-9d2e-7bee92741f0d.png align="center")
    

Push the image to a public or private repository docker push.

***docker push username/docker latest image***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683280224261/64e8915f-ae33-4ab8-b2d0-a70e253d40b9.png align="center")

*note:-In tag command provides the name of the latest image.*

Check we can successfully push the docker image on Docker Hub.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683281723893/1838c4c6-941b-47de-819e-d4df8516ffa6.png align="center")
