From charlesreid1

Git checkout the docker repo for mongodb: https://git.charlesreid1.com/docker/d-mongodb

Make the container with the make command

If the container is already made, just run the run_container script:

./run_container.sh

This will run the docker run command.

The final docker run command in the repo's scripts looks like this:

docker run \
    --name happy_mongo \
    -p <IP-ADDRESS-NUMBER-1>:27017:27017 \
    -p <IP-ADDRESS-NUMBER-2>:27017:27017 \
    -v /opt/mongodb:/data/db \
    -d \
    -ti jupitermongo

This starts a container with the name happy_mongo (the --name flag)

The -p flags bind this docker instance to two ports: one on the host's IP address IP-ADDRESS-NUMBER-1, the other on IP-ADDRESS-NUMBER-2.

The -v flag tells mongodb to mount the host's /opt/mongodb directory as the local data directory, to persist changes to the database.

The -d flag tells docker to run this in the background.

The -ti flag specifies which container to run (see build script).

To attach to the container once it is already running, use docker exec:

docker exec -ti happy_mongo /bin/bash

This will give you a shell inside the MongoDB docker machine. From there, you can debug problems in the container, update the database, run admin commands, etc.