docker-run-local
is a lightweight Docker-based local development environment that helps you spin up essential backend services like PostgreSQL, MongoDB, and more — with zero manual setup.
-
Docker GUI
is the easiest way to get off the ground. -
You can find instructions to install docker on Installing Docker
-
At the end of the installation, you need to make sure you’re able to run the following command -
docker run hello-world
-
Docker let’s you do a lot of things.
-
It let’s you
containerise
your applications. -
It let’s you run other people’s
code + packages
in your machine. -
It let’s you run common software packages inside a
container
(For eg - Mongo, Postgres etc)Window/Mac Machine ____________________________________________________ | | | | | Container Container | | ______________ ______________ | | | | | | | | | MongoDB | | Postgres | | | | | | | | | | 27017 | | 5432 | | | |______________| |______________| | | | |____________________________________________________|
- Just like you can push your
code
to Github/Gitlab. - You can push
images
to docker registries
-
Let’s say you wan’t to run MongoDB locally Docker MongoDB
docker run mongo
-
You will notice you can’t open it in
MongoDB Compass
-
The reason is that you haven’t added a port mapping
# docker run -p <local_port>:<container_port> mongo docker run -p 27017:27017 mongo
-
The
-d
flag will run the container in the background -
This will allow you to run the container and continue using the terminal for other commands.
docker run -d -p 27017:27017 mongo
-
This will show you all the containers you are running.
docker ps
-
Will stop the container that you are running
docker kill <container_id>
docker run -d -p 27017:27017 mongo
-
The connection string for this mongo would be
mongodb://localhost:27017
docker run -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
-
The connection string for this postgres would be
postgresql://postgres:mysecretpassword@localhost:5432/postgres