Dockerfile
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 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.
For more about Dockerfile visit here
Task
- Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)
Here, we are going to clone an open-source project and dockerize it.
- Build the image using the Dockerfile and run the container
let's look at the Dockerfile first
Let's break down the above Dockerfile into its components:
FROM
sets the base image to use. In this case, we are using version 3.9 of pythonWORKDIR
sets the working directory for the container to/app
.COPY
copies the application files into the container.RUN
runs a command to install any dependencies needed. In this case, we are updating the package list and installing Python 3.CMD
sets the command to run when the container starts.
Note that the instructions in a Dockerfile are executed in the order they are written. It is also important to use the correct syntax and formatting when writing a Dockerfile, as any mistakes can result in errors during the build process.
Now, after creating the Dockerfile, let's create the image using
sudo docker build . -t <tag>
Now run the docker image using
sudo docker run -d -p 8001:8001
here, -d means in the background (Daemon) mode and -p is used for port mapping. We have exposed our image to port 8001.
- Verify that the application is working as expected by accessing it in a web browser
to verify the application is running copy your IP and paste it into the browser
along with the colon and respective port number (ex. http://xx.xxx.xx.xx:8001)
- Push the image to a public or private repository (e.g. Docker Hub )
docker push <hub-user>/<repo-name>:<tag>
So, this is how you dockerize any open-source application and then publish it into your repository.
For Reference Project visit here
If you want to dive further, Watch bootcamp
You can share the learning with everyone over LinkedIn and tag us along ๐
Happy Learning:)
************************************************************************
Thanks for reading! Hope you find this helpful.
Happy learning !!!
Suggestions are always welcome.
Thank You - Shubham Londhe