Download image
# Docker pull the latest version of mongo image from the warehouse, if not tagged, the default obtain the latest version of the latest
docker pull mongo
Mounting data volumes and configuration files
Create a local path and mount Docker in the data
Create a local folder
mkdir -p /root/docker/mongo/conf && mkdir -p /root/docker/mongo/data
Create a container and start Mongo
docker run --name mongo-server \ -p 27017:27017 \ --mount type=bind,src=/root/docker/mongo/conf,dst=/data/configdb \ --mount type=bind,src=/root/docker/mongo/data,dst=/data/db \ --restart=on-failure:3 \ -d mongo
- --name : specify a name for the container
- -p : Specifies port mapping format: a host (host) port: the port of the container
- -e : username = "xxx", set the environment variable
- --restart = on-failure: 3 cycles restart case refers to a container in the future appear abnormal exit (exit code of non-0) three times:
- -mount : bind mounts
- -d : background container and return the container id
Running success!