Table of contents
📝Dockerfile:
A Dockerfile 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 Dockerfile 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:
Step 1: Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)
Intermediate Step 1: Create an AWS EC2 Instance 🌐
Navigate to the AWS Management Console.
Launch an EC2 instance, choosing an Amazon Machine Image (AMI) based on your preference (e.g., Amazon Linux).
Configure the instance, and set up security groups to allow inbound traffic on ports 22 (SSH) and 8000 (django-todo-app application).
Launch the instance and download the private key.
Connect to the instance using SSH:
Intermediate Step 2: Clone the repository from GitHub to your Ubuntu server using the command🔄
git clone https://github.com/LondheShubham153/node-todo-cicd.git
Intermediate Step 3: Create a Dockerfile📜
vim Dockerfile
The specific commands you can use in a docker file are:
FROM: The first thing we need to do is define from which image we want to build. Creates a layer from the node 12.2.0-alphine
WORKDIR a command is used to define the working directory of a Docker container at any given time.
COPY is a docker file command that copies files from a local source location to a destination in the Docker container.
RUN command to execute the command npm install and Build your container
CMD Specifies what command we want to run when our image is run inside of a container.
EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
Step 2: Build the image using the Dockerfile and run the container 🛠️
Intermediate Step 1:
To build an image using Dockerfile, Go to the directory that has your Dockerfile and run the command
docker build -t node-app .
✅To cross-check the images
docker images
Intermediate Step 2:
now can create a container using the command 🗑
docker run -d -p 8000:8000 node-app:latest
-d runs the container in detached mode, leaving the container running in the background.
-p flag redirects a public port to a private port inside the container
✅To cross-check the Container
docker ps
Step 3: Verify that the application is working as expected by accessing it in a web browser
Copy the public IPv4 address paste it into the browser url and add 8000 port.
Step 4: Push the image to a public or private repository (e.g. Docker Hub )
Intermediate Step 1 :
docker login
Intermediate Step 2 :
Tag the image with your Docker Hub username and repository name
docker tag node-app:latest sutish/node-app:latest
Intermediate Step 3 :
Push the image to Docker Hub
docker push sutish/node-app:latest
Intermediate Step 4 :
Verify the image sent to Docker Hub
📍 Conclusion
In conclusion, this Docker project for DevOps engineers guides you through the process of containerizing a Todo application. By creating a Dockerfile📜, building an image🛠️, running a container🗑, and pushing the image to a repository🖥️, you ensure consistency and reproducibility in deploying your Todo applications across different environments. 🌐
Thank you for reading!
Contact me on Linkedin 🤝
Check out my GitHub for more resources 📚