Skip to main content

Command Palette

Search for a command to run...

Ready, Set, Dockerize: Unleash Container Magic with My Very First Web App! ๐Ÿš€๐Ÿณ Day - 17

Published
โ€ข2 min read
V

๐Ÿ‘‹ Hello, I'm Vishal, an aspiring Information Technology enthusiast currently embarking on a journey towards a Bachelor's degree in Engineering. My passion lies in exploring the dynamic realms of cloud computing and DevOps technologies, where I constantly strive to bridge the gap between innovation and practical implementation.

๐Ÿ’ก As a student of Information Technology, I'm on a mission to absorb knowledge, solve real-world problems, and contribute to the tech community. My academic pursuits fuel my curiosity, and my hands-on experience with cloud and DevOps tools empowers me to navigate the evolving landscape of modern technology.

๐Ÿš€ Join me as I share insights, discoveries, and challenges encountered on this exciting educational and professional adventure. Let's connect, collaborate, and grow together in the ever-expanding world of IT.

๐Ÿ”— Connect with me on social media and let's build a network that fosters learning, sharing, and innovation.

Happy coding! ๐ŸŒŸ

Introduction

Ahoy, fellow tech enthusiasts! Today marks the launch of an exciting journey into the world of Docker. Join me as we embark on the maiden voyage of containerization, unleashing the power of Docker to build and deploy my very first web application. Buckle up for a thrilling adventure in which we set sail, navigating the seas of Docker, and witness the magic of containerization.

Setting the Stage: Crafting the Dockerfile

Our journey begins with the creation of a Dockerfile, the blueprint that will guide Docker in constructing a perfect container for our web application. Let's dive into the command seas and set sail with the following Dockerfile:

# Use an official Node.js runtime as a base image
FROM node:14

# Set the working directory in the container
WORKDIR /usr/src/app

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

# Install app dependencies
RUN npm install

# Copy the application source code to the container
COPY . .

# Expose the port on which the app will run
EXPOSE 3000

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

Crafting My Very First Web Application

For this inaugural Docker project, let's keep it simple. Assume that I have the Node.js web application code files in the current directory.

Docker Magic: Building and Running the Container

With our Dockerfile in hand, let's execute the magic commands to build and run our container:

# Build the Docker image
docker build -t my-web-app .

# Run the Docker container
docker run -p 8080:3000 -d my-web-app

Voila! My web application is now sailing smoothly at http://localhost:8080.

Testing the Waters: Verifying Application Functionality

To ensure a successful voyage, I open my web browser and navigate to http://localhost:8080. Behold the beauty of my containerized web applicationโ€”it's alive and thriving!

Docking at Repositories: Pushing to Docker Hub

As my ship continues to sail the DevOps seas, it's time to share my creation with the world. Safely docking my container at Docker Hub, I execute the following commands:

# Log in to Docker Hub (prompted for credentials)
docker login

# Tag my image
docker tag my-web-app <my-docker-hub-username>/my-web-app

# Push the image to Docker Hub
docker push <my-docker-hub-username>/my-web-app

My Dockerized web application is now securely harbored at Docker Hub, ready for others to embark on their own maiden voyages.

More from this blog

Untitled Publication

81 posts