DEV Community

Cover image for Docker Simplified: Create Your First Container in 5 mins!🐳
Harshit Rawat
Harshit Rawat

Posted on

22

Docker Simplified: Create Your First Container in 5 mins!🐳

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

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

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!
Vscode

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

Enter fullscreen mode Exit fullscreen mode

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"]

Enter fullscreen mode Exit fullscreen mode
  • 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"

docker1

  • 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
Enter fullscreen mode Exit fullscreen mode

We are mapping the containers port to our host machine port so that it can run the application.
docker2

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.

dockerimage

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.

Container

This is the application you should see!

Final Image

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!!

Thankyou

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (4)

Collapse
 
hostmycode1 profile image
HostMyCode

This is a great guide for beginners looking to dive into Docker! The step-by-step process makes it easy to create your first container in no time. Definitely a must-try for anyone wanting to streamline app deployment!

Collapse
 
harshit_rwt profile image
Harshit Rawat

Thankyou so much for such a positive feedback ✨
Glad you liked it 😊

Collapse
 
bobbyiliev profile image
Bobby Iliev

Cool post! Well done!

For anyone who wants to learn more, check out this free eBook:

GitHub logo bobbyiliev / introduction-to-docker-ebook

Free Introduction to Docker eBook

💡 Introduction to Docker

This is an open-source introduction to Docker guide that will help you learn the basics of Docker and how to start using containers for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you will most likely have to use Docker at some point in your career.

The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Docker.

🚀 Download

To download a copy of the ebook use one of the following links:

📘 Chapters

Collapse
 
np_omar profile image
Omar Saunders

Nice!!!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay