Updated on: Mon Mar 29 2021
When working on pet projects I constantly need to some of postgresql or mongodb instance to run. For me the best way to achieve this without polluting the entire system by globally installed database engines is to use docker.
First pull appropriate postgresql docker image. It's a lot of them in the list. Here I use some stable release of version 12. And I use it's alpine prefixed version to run it without any additional features, only stuff needed to run database is included into this image.
copied bash
docker pull postgres:12.3-alpine
To run a container:
copied bash
docker run --rm --name test-name -e POSTGRES_PASSWORD=123321 -p 8084:5432 postgres:12.3-alpine
copied bash
docker pull mongo:4.2-bionic
copied bash
docker run --rm --name test-mongo -p 27018:27017 -d mongo:4.2-bionic
Connection to mongo via nodejs in this case could be established without providing any username/password credentials and could look like this:
copied javascript
const client = new MongoClient(
"mongodb://localhost:27018/?poolSize=20&writeConcern=majority",
{
useUnifiedTopology: true,
}
);