Day 17 Task: Docker Project for DevOps Engineers

Day 17 Task: Docker Project for DevOps Engineers

Table

Β·

4 min read

Introduction
Dockerfile
Task
Conclusion

IntroductionπŸ“–πŸŽ¬

πŸš€ Welcome to Day 17 of our DevOps journey! Today, we embark on an exciting adventure into the world of Docker, a revolutionary containerization platform. As DevOps Engineers, our goal is to streamline the software development lifecycle, and Docker plays a pivotal role in achieving this objective. Imagine a scenario where deploying, scaling, and managing applications becomes as simple as executing a single command. Docker empowers us to encapsulate applications, dependencies, and configurations in lightweight, portable containers, transforming the way we develop, ship, and run software. So, let's set sail on this exhilarating Docker journey together, where innovation and collaboration are the guiding stars! 🐳🌟✨

ΛšΛ–π“’Φ΄ΰ»‹πŸŒ·Ν™Φ’βœ§Λš.πŸŽ€ΰΌ˜β‹†ΛšDockerfileΛ–π“’Φ΄ΰ»‹πŸŒ·Ν™Φ’βœ§Λš.πŸŽ€ΰΌ˜β‹†

"The Dockerfile is like a recipe that includes everything needed to run an application. With Docker, programmers can easily create, share, and manage containers – self-contained units for running applications. There's a version for big projects (Enterprise Edition) and a simpler one (Community Edition) for smaller teams learning Docker."

Docker

The Dockerfile uses DSL (Domain Specific Language) and contains instructions for generating a Docker image. Dockerfile will define the processes to quickly produce an image. While creating your application, you should create a Dockerfile in order since the Docker daemon runs all of the instructions from top to bottom.

What is Docker Container?

A container is a runtime instance of an image. Containers make development and deployment more efficient since they contain all the dependencies and parameters needed for the application it runs completely isolated from the host environment.

Dockerfile commands/Instructions

1. FROM

Represents the base image(OS), which is the command that is executed first before any other commands.

Syntax:

FROM <ImageName>

2. COPY

The copy command is used to copy the file/folders to the image while building the image.

Syntax:

COPY <Source> <Destination>

3. ADD

While creating the image, we can download files from distant HTTP/HTTPS destinations using the ADD command.

Syntax:

ADD <URL>

4. RUN

Scripts and commands are run with the RUN instruction. The execution of RUN commands or instructions will take place while you create an image on top of the prior layers (Image).

Syntax:

RUN < Command + ARGS>

5. CMD

The main purpose of the CMD command is to start the process inside the container and it can be overridden.

Syntax:

CMD [command + args]

6. ENTRYPOINT

A container that will function as an executable is configured by ENTRYPOINT. When you start the Docker container, a command or script called ENTRYPOINT is executed. It can’t be overridden.The only difference between CMD and ENTRYPOINT is CMD can be overridden and ENTRYPOINT can’t.

Syntax:

ENTRYPOINT [command + args]

Create a Dockerfile

Dockerfile Creation:

  • Use an official Python image as the base.

  • Set the working directory.

  • Copy the requirements.txt file and install Python dependencies.

  • Copy the entire application code.

  • Expose port 5000.

  • Set the command to run the application using Python (app.py assumed).

  • Create requirements.txt:

    • List Python dependencies, e.g., Flask==1.1.2.
  • Create Python Web App (app.py):

    • Develop a simple Flask web application.
  • Build Docker Image:

    • Execute docker build -t my-python-app . to create a Docker image named my-python-app.
  • Run Docker Container:

    • Execute docker run -p 5000:5000 -d my-python-app to run the Docker container in the background, mapping port 5000.

Push the image to a public or private repository

  1. Tag the Docker image:

    • Give your Docker image a recognizable name and tag.
  2. Push the Docker image:

    • Log in to the Docker repository.

    • Upload your tagged Docker image to the repository.

πŸ‘‰πŸ‘‰πŸ‘‰ConclusionπŸ”šπŸ”š

πŸš€ Welcome to Day 17 of our DevOps journey! Today, we explored Docker, a cool tool changing how we work with software. Think of it like magic making apps super easy – that's Docker! In this fun Docker ride, we figured out how to pack apps in simple containers, making software run better. With creativity and teamwork, Docker helps us work smarter and be successful. Cheers to more cool things on your Docker adventure! 🐳🌟✨

Β