Day 17 Task: Docker Project for DevOps Engineers

Day 17 Task: Docker Project for DevOps Engineers

Introduction 🌟

Docker is a containerization platform that simplifies the process of packaging and running applications. It's like a magic box where you can put all your application's dependencies and ship it across different environments without worrying about compatibility issues. Docker containers are lightweight, efficient, and provide consistency from development to production.

In today's task, we will walk you through the process of creating a Dockerfile for a simple web application, building an image from it, running a container, and finally, pushing the image to a public or private repository like Docker Hub.

2. Tasks 📋

2.1 Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)🤔

Let's start by creating a Dockerfile for a straightforward web application. You can choose your preferred language, but for this example, we'll consider a Node.js app. Your Dockerfile should look something like this:

# getting base image
FROM node:12.2.0-alpine

# working dirctory where all code will be kept
WORKDIR app

# copy the app to the current working directory of container
COPY . .

# compile code
RUN npm install

# run the test cases
RUN npm run test

# expose the port
EXPOSE 8000

# run the compiled code
CMD ["node","app.js"]

2.2 Build the image using the Dockerfile and run the container🛠️

Once you've created the Dockerfile, navigate to the directory where it's located and run the following commands:

docker build . -t node-app
docker run -d -p 8000:8000 node-app:latest

This will build the Docker image

To start a container from this image run your web application on port 8080.

docker run -d -p 8000:8000 node-app:latest

2.3 Verify that the application is working as expected by accessing🖥️

go to EC2 instance >security groups, and add inbound rule port 8000 .....

Open your web browser and navigate to http://localhost:8080. You should see your application up and running. Congratulations, you've containerized your web app!

2.4 Push the image to a public or private repository (e.g. Docker Hub )🧮

Now, it's time to share your containerized application. Push the Docker image to a public or private repository like Docker Hub. First, log in with your Docker Hub credentials using:

docker login

Then, tag your image and push it to the repository:

# tag the image
sudo docker tag node-app:latest mgupt21/node-app:latest

# push image to the repository
sudo docker push mgupt21/node-app:latest

Conclusion 🎉

In this project, you've taken a hands-on approach to Docker, an essential technology for DevOps engineers. You've learned how to create a Dockerfile, build an image, run a container, and even share your application with the world.

Docker makes it easier to manage dependencies, deploy applications consistently, and collaborate with other developers. It's a fundamental tool in the DevOps world, and mastering it will significantly boost your productivity.

Keep practicing and exploring the world of DevOps, and stay tuned for more exciting tasks in our DevOps journey. 🚢💡

Happy Dockering! 🐳🔧✨