Run MongoDB in local environment using Docker

Running MongoDB in local environment using Docker without installing the MongoDB server would be my preference since I use Docker. The reason is obvious, I don’t want to clutter my development environment with a bunch of database server installations.

With Docker installed on development environment I could just simply execute the following command to spin up a new MongoDB server running in a container:

docker run -d -p 27017:27017 –name=local-mongodb mongo:3.6

But, still to connect with the database you would need a client, in my case, I simply installed the mongodb-org-shell and use it to connect to the MongoDB database running in the container. The earlier command I showed to you will run the MongoDB container and expose the 27017 port to the host machine. Connecting to the MongoDB in the container would simply just executing the following command on the CLI:

mongo

I use this approach in several projects, and I am quite happy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s