Use Docker Like Nobody Else π«
Table of Contents
Setting up a development environment can be a daunting task. Imagine you need to work with the MERN Stack. Hereβs what you typically need to do:
- Install nvm or any Node.js version.
- Install the MongoDB server.
- If a package doesn’t support your current Node.js version, you have to install a new one.
- Keeping all these running on your local machine can be cumbersome and may cause conflicts.
So, how can we make this process easier to manage and isolate? The answer is Docker. Let’s dive in!
Installing Docker
Here’s a simple script to install Docker on any Linux distro:
curl -o- https://get.docker.com | sh -x
Running a Node.js Application with Docker
First, navigate to your working directory and run the following command:
sudo docker run -it -v $(pwd):/srv -w /srv -p 3000:3000 node:current npm run start:dev
- -it : interactive terminal
- -v: volume mount
- -w: working directory
- -p: port forwarding
This command runs a Vite React.js project:
sudo docker run -it -v $(pwd):/srv -w /srv -p 5173:5173 node:current npm run dev
Running MongoDB with Docker
sudo docker run -d -p 27017:27017 --name my-demo-mongo mongo
By using Docker, you can easily manage and isolate your development environment, avoiding conflicts and making the setup process much smoother.