Skip to main content

Command Palette

Search for a command to run...

Day 17 Task: Docker Project for DevOps Engineers

Published
3 min readView as Markdown
Y

🚀 Aspiring DevOps & DevSecOps Engineer | Cloud DevOps (Azure & AWS) | Automation & Security Champion | Passionate Learner🌐

Hi, I’m Yuvraj! 🔥 I'm embarking on an exciting journey in the world of DevOps & DevSecOps, armed with hands-on expertise and a drive to excel. From automating tasks to building robust CI/CD pipelines, I’m dedicated to turning complex challenges into efficient and secure solutions.

What I Bring to the Table: ●Linux & Shell Scripting 🖥️ Automating processes and mastering command-line operations.

●Git & Git Branching 🔀 Seamless version control for effective collaboration.

●Build Tools 🔧 (Maven & npm) Crafting stable builds for quality software.

●CI/CD Tools 🚄 (Jenkins, GitHub Actions, Azure DevOps, GitLab CI/CD) Ensuring smooth & automated deployments.

●Security in DevOps 🛡️ Embedding security at every stage to safeguard development processes.

●Artifact Management 📦 (Nexus & Azure Artifacts) Managing software versions efficiently.

●Containerization & Orchestration 🐳⎈ (Docker & Kubernetes) Deploying scalable, agile applications.

●Infrastructure as Code (IaC) 📜 (Terraform & Ansible) Automating environment provisioning.

●Monitoring & Troubleshooting 🔍 Keeping systems in check with proactive issue resolution.

●Real-world & Corporate Projects 🌟 Hands-on experience with practical implementations.

✨ Always eager to learn, collaborate, and innovate! ✨ I’m ready to transform my academic knowledge and project experiences into real-world impact. Let’s connect and explore how we can drive meaningful change together! 🤝

Dockerfile

Docker is a tool that makes it easy to run applications in containers. Containers are like small packages that hold everything an application needs to run. To create these containers, developers use something called a Dockerfile.

A Dockerfile is like a set of instructions for making a container. It tells Docker what base image to use, what commands to run, and what files to include. For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.

Here are some of the most commonly used commands in a Dockerfile:

  • FROM: Specifies the base image (Python, Nodejs image....etc from Docker Hub).

  • WORKDIR: Sets the working directory inside the container.

  • COPY: Copies the current directory's content (Python,nodejs....etc web app files) to the /app directory in the container.

  • RUN: Executes commands in the container (here, it installs the dependencies listed in requirements.txt).

  • EXPOSE: Exposes a port (your port no in this case) from the container to the host.

  • ENV: Sets environment variables (here, sets NAME to "your name").

  • CMD: Specifies the command to run the application when the container starts (here, it runs app.pyor app.js).

Task

  • Create a Dockerfile for a simple web application (e.g. a Node.js or 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)

  1. Create a Simple Python Flask Web Application:

  • Create a simple Python Flask application. Let's say it's a basic server that responds with "Hello DevOps engineer" when accessed.

  • app.py (Python Flask application):

  1. Create a Dockerfile:

  1. Build the Docker Image:

  • Navigate to the directory containing app.py and Dockerfile.

  • Run the following command to build the Docker image:

docker build -t python-web-app-1.0 .

  1. Run the Container:

  • Once the image is built, run a container based on this image:
docker run -d --name python-web-app-1.0 -p 5000:5000 python-web-app-1.0:latest

  1. Verify the Application:

    • Access the application by opening a web browser and navigating to http://IP adress:5000. You should see "Hello DevOps engineer" displayed.

  1. Push the Image to a Repository (e.g., Docker Hub):

Log In to Docker Hub 🔑

  • If you haven't already, you need to log in to your Docker Hub account in your terminal:
docker login

Enter your Docker Hub username and password when prompted.

  • Before pushing the image to Docker Hub, you need to tag it with your Docker Hub username and repository name. Replace <username> with your Docker Hub username and <repository> with the desired repository name:
docker tag <your_image_name> <dockerhub username>/<repository_name>:tag

Push the Image to Docker Hub 🚢

  • Push the tagged image to Docker Hub:
docker push <dockerhub username>/<repository name>:tag

More from this blog

Y

yuvrajdevops

38 posts

🚀 Aspiring DevOps & DevSecOps Engineer | Cloud DevOps (Azure & AWS) | Automation & Security Champion | Passionate Learner🌐