gerandonk/mongo
mongodb 4.4 ubuntu 20.04
16
Start MongoDB using:
docker run --name mongodb -d --restart=always \
--publish 27017:27017 \
--volume /srv/docker/mongodb:/var/lib/mongodb \
gerandonk/mongo:4.4
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
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
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 gerandonk/mongo