🛠 Introduction
In this post, I will show you how to quickly and easily set up Docker for your project to make development and deployment easier.
🎯 Why use Docker?
Environment isolation: code runs the same on any machine.
Ease of deployment: launch a project with a single command.
Time saving: no need to manually install dependencies.
🔧 Installing Docker
Download and install Docker from the official website>
Let's check that everything is installed:
docker --version
🏗 Creating a Dockerfile
Let's create a Dockerfile in the root of the project:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
What's going on here?
FROM — take the Node.js image.
WORKDIR — set the working directory.
COPY — copy files.
RUN — install dependencies.
CMD — run the project.
🔥 Building and running the container
Now let's build the image and run the container:
docker build -t my-app .
docker run -p 3000:3000 my-app
🎉 Summary
Now your project is running in a Docker container! 🚀