Day 2 : Dockerize a TODO Project
"Join us today as we explore Docker, a powerful tool for containerizing our TODO project. We'll create a straightforward setup that ensures our application runs consistently across different environments. By the end of this blog, our task manager will be packaged and ready for deployment anywhere, minimizing setup hassles. Let’s dive in and discover how Docker can streamline and simplify our development process."
Get started
Step -1 : Clone github repository
# clone github repository
git clone https://github.com/docker/getting-started-app.git
#cd to the directory
cd getting-started-app/
Step -2 : Create Empty Dockerfile
# Empty file with name of Dockerfile
touch Dockerfile
Step -3 : Open the file using a text editor
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
FROM node:18-alpine: Start with a basic version of Node.js
WORKDIR /app: Set up a folder inside the container called ‘/app’ where our project will live.
COPY . . : Take all the files from our project on the computer and put them into the ‘/app’ folder inside the container.
RUN yarn install --production: Install only the necessary parts of our project to make it run .
CMD [“node”, “src/index.js”]: Executing our container using Node.js when it turns on.
EXPOSE 3000: port 3000.
Step -4 :Docker Build
yum install docker
# Run Docker Daemon
systemctl start docker
# Build an image from Dockerfile
docker build -t todo-project .
Verify Docker Image
docker images
Step -5 :Create a public repository on Docker hub
Visit Docker Hub: Go to hub.docker.com.
Start New Repository: Click on ‘Create Repository’ in the ‘Repositories’ section.
Name Your Repository: Enter a name for your new repository.
docker login
docker tag todo-project:latest vaibhav871/todo-repo:latest
Step -6 : Push Docker Image to the Repository
docker push vaibhav871/todo-repo:latest
Step -7 : Pull the image into another environment ( Dev , Test , Production )
docker pull vaibhav871/todo-repo:latest
Step -8 :Run docker container
docker run -dp 3000:3000 vaibhav871/todo-repo:latest
Done for the day . We successfully containerized TODO application . 🎉🎉
Thank you for reading! Let's continue learning, growing, and making a positive impact in the tech world together.
Subscribe to my newsletter
Read articles from Vaibhav Jaiswal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by