Hi Everyone! Today, I'll be discussing how to run Docker containers in five minutes or less. If you are beginner this one is for you. While this isn’t a comprehensive Docker tutorial but a Project, I’ll provide enough information to get you started. If you find this topic interesting and would like a more detailed tutorial on Docker, please let me know by commenting down! Before we dive into the practical steps, let’s start with a brief of what Docker is?
Docker
Imagine you're working on a web application with your team, and each of you has a different setup on your machines. You finish your part, but when you share it with a colleague, it doesn't work because of mismatched software versions or missing dependencies. This is Frustrating!
And that's where Docker comes in. Docker allows you to package your application and everything it needs to run—like libraries and configurations—into a single unit called a Container. When you create a Docker container, it runs the same way on any machine, whether it's your local computer, a colleague's laptop, or a production server.
We will be creating those containers in this blog.
Prerequisites
- Version Control: A basic Knowledge of Git & Github is required.
- Docker: Docker should be installed in you system. Install from the official docs Docs or Follow these quick videos Docker for Windows, Docker for Mac, Docker for Linux.
- Docker Dekstop: To see you containers running you need Docker Desktop. It provides a user-friendly graphical interface (GUI) that allows users to manage their containers, applications, and images with ease. Download Docker Dekstop Get Started
- Nodejs Should be installed in your system.
Project Flow
Let's Begin
- Clone the Repository : The First step is to go to github and clone this repository in your local system. Also, make sure to give it a star 🥺.
You should be able to see the project setup correctly!
Now that you have cloned the project set up the required dependencies.
Run the following commands in your terminal
cd project # Navigate to your project directory
npm install # Install the required packages
Dockerfile
A Dockerfile is a text document that contains a series of instructions for building a Docker image. Each instruction in the Dockerfile specifies how to set up the environment, install dependencies, and configure the application. When you run the Docker build command with a Dockerfile, it processes these instructions sequentially to create an image. Once the image is built, it can be run as a container.
If you want to learn more about Dockerfiles comment down
Here's our Dockerfile
FROM node:18-alpine
WORKDIR /src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev"]
- Since our project already have a Dockerfile, lets build Docker images. Open your Docker Dekstop and come back to your Code editor.
Run the following docker command to create/build a docker image, in your terminal. Don't worry about what the command is & how it is working, right now!
docker build -t taskmaster .
Don't forget to add the dot at the end .
You can name your image whatever you want i named it "taskmaster"
- Now that we have build our docker image lets run it. Run the following command in your terminal
docker run -it -d -p 3000:3000 taskmaster
We are mapping the containers port to our host machine port so that it can run the application.
The command gives an id associated with our Image.
- Go back to Docker Dekstop and you can see your docker image that you just build.
Click on the "In use" option and you will see the docker container running, if not click on the "Actions" icon in the containers section to run your Container.
This is the application you should see!
Your Docker container is up and running, You did it! You ran your first docker container all by yourself, Congratulations 👏🎉🎉
Conclusion
Thank you if you are still reading the blog and have implemented the project. we took a hands-on approach to running Docker containers, focusing on practical execution. We successfully launched our first Docker container, demonstrating how easy it is to get started with containerization.
Although this was not a docker tutorial but If you're interested in a more detailed explanation of Docker's features & concepts, please let me know in the comments! Your feedback really matters. Share it on socials, with your friends about the container you created all by yourself, tag me on X and keep Learning. I truly value your insights and perspectives. If you come across anything that seems off or could be improved, please don’t hesitate to leave a comment.
I hope you enjoyed the content, please consider sharing it with someone who might benefit from it. Feel free to reach out to me on Twitter, LinkedIn, Youtube, Github.
Thankyou Once Again!!
Top comments (0)