gerandonk/mongo

By gerandonk

Updated about 2 months ago

mongodb 4.4 ubuntu 20.04

Image
Databases & Storage

16

Quickstart

Start MongoDB using:

docker run --name mongodb -d --restart=always \
  --publish 27017:27017 \
  --volume /srv/docker/mongodb:/var/lib/mongodb \
  gerandonk/mongo:4.4

Command-line arguments

You can customize the launch command of the MongoDB server by specifying arguments to mongod on the docker run command. For example the following command prints the help menu of mongod command:

docker run --name mongodb -it --rm \
  --publish 27017:27017 \
  --volume /srv/docker/mongodb:/var/lib/mongodb \
  gerandonk/mongo:4.4 --help

Persistence

For MongoDB to preserve its state across container shutdown and startup you should mount a volume at /var/lib/mongodb.

The Quickstart command already mounts a volume for persistence.

SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker:

mkdir -p /srv/docker/mongodb
chcon -Rt svirt_sandbox_file_t /srv/docker/mongodb

Logs

To access the MongoDB logs, located at /var/log/mongodb, you can use docker exec. For example, if you want to tail the logs:

docker exec -it mongodb tail -f /var/log/mongodb/mongod.log

Docker Pull Command

docker pull gerandonk/mongo