Day 2 of #40DaysOfKubernetes: Dockerizing the Application
Welcome back to Day 2 of #40DaysOfKubernetes! Today, we dive into the world of Docker, focusing on how to dockerize an application. Here’s a rundown of what we covered today:
1. Playing with Docker (Sandbox)
We began by exploring the Docker playground, an online sandbox environment where you can try out Docker commands without needing to install anything on your local machine. This is a great way to get hands-on experience with Docker in a controlled, risk-free environment.
2. Docker Desktop
Next, we installed Docker Desktop, a comprehensive tool that provides a user-friendly interface to work with Docker containers. It simplifies the process of building, running, and managing containers on your local machine.
3. Cloning a GitHub Repository
To practice Docker commands, we cloned a sample GitHub repository containing a simple todo application. This application will be our guinea pig as we learn to dockerize it.
git clone https://github.com/docker/getting-started-app.git
cd getting-started-app/
4. Writing the Dockerfile
The Dockerfile is a crucial part of dockerizing any application. It contains a series of instructions that Docker uses to build an image. Here’s the Dockerfile we wrote for our Node.js todo app:
FROM node:20-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
5. Building the Docker Image
With the Dockerfile in place, we built our Docker image. This image contains everything needed to run our application.
docker build -t todo .
We then explored Docker Hub, a cloud-based repository where you can store and share your Docker images. We created an account and set up a repository for our todo app.
docker images
7. Pushing the Docker Image
After building the image locally, we pushed it to our remote repository on Docker Hub. This allows others to pull and run our application easily.
docker push christobersg/todo-repo:latest
8. Pulling the Docker Image
To verify that our image was successfully uploaded, we pulled it from Docker Hub to a different environment.
docker pull christobersg/todo-repo:latest
9. Running the Docker Container
Finally, we ran our Docker container. This step launched the todo application on port 3000.
docker run -p 3000:3000 christobersg/todo-repo:latest
By the end of today, our todo app was up and running in a Docker container, accessible at http://localhost:3000
.
Summary
Today was all about getting comfortable with Docker and understanding the process of dockerizing an application. We started with a sandbox, moved to Docker Desktop, and then proceeded to write a Dockerfile, build an image, push it to a remote repository, and run it locally. Each step reinforced the core concepts of Docker, bringing us closer to mastering containerization in Kubernetes.
Link for the reference : https://youtu.be/nfRsPiRGx74?si=r9VKREd1sxa--7JB
Stay tuned for tomorrow’s adventures as we continue our journey through #40DaysOfKubernetes!