🚀 My Docker & DevOps Learning Journey Begins! 🚀

Mohd SalmanMohd Salman
3 min read

Day 4: Diving Deeper into Docker Commands and Creating My First Dockerfile 🚀

Today was an exciting step forward in my Docker & DevOps journey! I explored some essential Docker commands and learned how to create and work with Dockerfiles. Here’s a recap of what I learned and implemented today.

🧠 What I Learned Today

Docker Commands

I spent some time getting familiar with a couple of key Docker commands that are crucial for managing images and containers:

  • docker build: This command is used to build an image from a Dockerfile. It's like compiling a recipe to create an executable.

      docker build -t my-app .
    

    This will create an image named my-app based on the instructions in the Dockerfile.

  • docker pull: This command allows you to pull an image from Docker Hub to your local machine.

      docker pull image1
    

    This pulls the Node.js base image with version 20 from Docker Hub, which you can later use in your Dockerfile.

Dockerfile Basics

One of the most important things I tackled today was creating my first Dockerfile. A Dockerfile is essentially a blueprint that defines how to build a Docker image. It contains a set of instructions for assembling an image, including installing dependencies, copying files, and setting up the working environment.

Here’s a breakdown of the commands I used in my Dockerfile:

  • FROM: Every Dockerfile starts with the FROM command, which defines the base image. In this case, I used the node:20 image as my base to ensure I had a Node.js environment ready to go.

      FROM node:20
    
  • WORKDIR: This command sets the working directory inside the container where all the files will reside. It helps in organizing the container's file structure.

      WORKDIR /app
    
  • COPY . .: This command copies everything from the current directory on your local machine into the working directory inside the container.

      COPY . .
    
  • RUN npm install: This is the command that installs all dependencies required for a Node.js application. It essentially runs npm install inside the container.

       RUN npm install
    

By the end of today, I was able to successfully build and run my own Docker image using the Dockerfile I created! 🚀

🔥 Takeaway

Learning these Docker commands and understanding how to create Dockerfiles is a fundamental part of mastering Docker. It not only simplifies the process of building and deploying applications but also ensures consistency across different environments.

I still have more commands to explore, so I’ll be diving deeper and sharing more soon!


What’s Next?

In the next few days, I’ll be covering more Docker commands, including how to manage containers more efficiently. Stay tuned for more updates as I continue on this journey of mastering Docker & DevOps!


🔗 Follow My Docker & DevOps Journey!
I’ll be learning and posting daily updates, sharing challenges, solutions, and practical examples along the way. You can follow my progress using the hashtag: #SalmanDockerDevOpsJourney.


Feel free to connect with me on LinkedIn or follow along with the hashtag!

0
Subscribe to my newsletter

Read articles from Mohd Salman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohd Salman
Mohd Salman