Skip to main content

Command Palette

Search for a command to run...

Day 17 - Embracing DevOps with Docker (Dec 13, 2023)

Updated
•2 min read
Day 17 - Embracing DevOps with Docker  (Dec 13, 2023)

Hello DevOps enthusiasts! šŸš€ We hope you're enjoying the #90daysofdevops journey as much as we are. Today's challenge is extra special because it involves diving into the world of Docker—a powerful tool for containerization. Get ready for some hands-on action as we embark on a Docker project designed for DevOps engineers.

Understanding Dockerfile

At the heart of Docker is the Dockerfile—a set of instructions that guides the creation of containers. Containers are lightweight, portable, and contain everything an application needs to run. In essence, it's like packaging your application and its dependencies into a neat, isolated box.

What's Inside a Dockerfile?

A Dockerfile typically includes instructions like selecting a base image, copying files, running commands, and setting up the environment. For instance, if you're creating a container for a web application, your Dockerfile might instruct Docker to use an official web server image, copy your website files, and start the server when the container launches.

šŸ‘‰ For a deep dive into Dockerfiles, check out the official documentation here.

Today's Task: Building a Simple Web App Container

Steps to Conquer the Challenge:

  1. Create a Dockerfile:

    • Choose a web application framework (e.g., Node.js, Python).

    • Write a Dockerfile with instructions for building a container.

    # Use an official base image
    FROM node:14

    # Set the working directory
    WORKDIR /app

    # Copy package.json and package-lock.json to the working directory
    COPY package*.json ./

    # Install dependencies
    RUN npm install

    # Copy the rest of the application files
    COPY . .

    # Expose a port (e.g., 3000) that the app will run on
    EXPOSE 3000

    # Command to run the application
    CMD ["npm", "start"]

  1. Build and Run the Container:

    • Use the Dockerfile to build an image.
    docker build -t my-web-app .

  • Run a container based on the created image.
    docker run -p 3000:3000 my-web-app

  1. Verify Your Application:

    • Access the running application in a web browser at http://localhost:3000 to ensure everything is working smoothly.
  2. Push to a Repository:

    • Share your creation with the world! Push the image to a public or private repository like Docker Hub.
    docker login
    docker tag reddit:latest hassanb111/reddit:latest
    docker push hassanb111/reddit:latest

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.