Docker MongoDB Container (for Ubuntu)

Installing docker (on Ubuntu):

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04

I started the mongo container with this:

sudo docker run --name mongodb -d -p 27017:27017 mongo

The running container name is mongodb (the image name is mongo) port 27017 on the container is exposed(published) as port 27017 on the host machine

Note that when the container is stopped, all data on the mongo db will be destroyed

To stop the container:

sudo docker stop mongodb

You also have to remove the container if you want to relaunch it with different conditions:

sudo docker rm mongodb

To keep the data run it like this:

sudo docker run --name mongodb -d -v /home/niall/mongo-data:/data/db -p 27017:27017 mongo

This will instruct the container to store the data (from /data/db on the container) to /home/naill/mongo-data)

To verify it's running:

sudo docker ps -a

Install Compass:

wget https://downloads.mongodb.com/compass/mongodb-compass_1.35.0_amd64.deb
sudo dpkg -i mongodb-compass_1.35.0_amd64.deb

To start compass:

mongodb-compass

You should be able to use compass to connect to the mondgo db container on mongos default port of 27017