🐬Day 17 - Docker Project for DevOps Engineers.

👋 Hello there! I'm Vivek, a DevOps enthusiast with a keen interest in streamlining software delivery. I hold a Master's degree in Computer Applications and have a solid foundation in key technologies such as Linux, Git, Docker, Kubernetes, and AWS.
💻 My passion lies in automation, ensuring efficient and seamless processes throughout the software development lifecycle. I thrive on creating robust CI/CD pipelines that empower teams to deliver high-quality software with confidence.
🚀 Beyond the code, I enjoy the ever-evolving world of DevOps and the challenges it brings. Join me on this journey as I explore new ways to enhance software delivery and foster a culture of continuous improvement.
Let's connect, collaborate, and make the world of DevOps even more exciting together
🐋Docker
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 Docker file.
🐋Docker file
A Docker file 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 Docker file 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.
✔Task
Create a Dockerfile for a simple web application
# Use official Node.js image as base
FROM node:14
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to container
COPY package*.json ./
# Install app dependencies
RUN npm install
# Copy the rest of the application code to container
COPY . .
# Expose port 3000 to the outside world
EXPOSE 3000
# Command to run the application
CMD ["node", "app.js"]
Build the Image and Run the Container
To build the Docker image, navigate to the directory containing the Dockerfile and run:
docker build -t my-node-app . #command for build the Docker Image
Run the container using:
docker run -d -p 3000:3000 my-node-app
This command runs the container in detached mode (-d), exposing port 3000 of the container to port 3000 on your host system (-p 3000:3000).
To verify that the application is working, you can open a web browser and navigate to http://localhost:3000.
Push the image to a public or private repository (e.g. Docker Hub )
To push the image to a Docker repository, first, you need to tag the image appropriately with your repository name. For example:
docker tag my-node-app yourusername/my-node-app
Then, you can push the tagged image to the repository:
docker push yourusername/my-node-app
Replace yourusername with your Docker Hub username or the name of your private repository. This will push the image to Docker Hub or your private repository.
Happy learning😊




