Docker Project for DevOps Engineers (Part-2)

Let's delve deeper into the Docker project. In today's exploration, we'll examine the Dockerfile and explore its practical application in deploying Python projects.

Dockerfile

Docker simplifies the process of running applications through containers, which are compact packages containing all the necessary components for an application to function. Developers leverage a Dockerfile to craft these containers, providing a set of instructions that guide Docker in selecting a base image, executing specific commands, and incorporating essential files. For instance, when creating a container for a website, the Dockerfile might instruct Docker to utilize an official web server image, import the website files into the container, and initiate the web server upon container startup.

To understand the concept practically, will perform the below task.

Task:

  • Create a Dockerfile for a simple web application (Python app)

    - Let's create a Dockerfile for a simple web application. where we kept our Python app, (Will pull Python app code in a folder and create a dockerfile in the same folder). The Dockerfile will guide the containerization process.

    We have pulled our source code and we can see the respective files in a folder. Now we create a Dockerfile with the below code which helps us to build an image through which we can create a container.

  • 2 . Build the image using the Dockerfile ( sudo docker build -t todo-app .)

    Once we hit enter post build command we could see interactive images are building as per the steps we have defined in our docker file.

  • post completing the command we could see todo-app image had been created in our local machine.

    3. We will run the image and create a container using sudo docker run -d -p 8001:8001 todo-app:latest

    Will verify with ps command if there process has been started for our container.

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

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

  • - Using the tag command first we tag our image with dockerhubusername/image-name.

  • Now we can push our image to dockerHub with the Push command

  • We could see the image now pushed in dockerHub.

  • I hope this task offers you a firsthand experience of real-time project deployment. In the upcoming session, we will delve into more advanced concepts.

Thanks,

Kishor Chavan