- Select the version of the docker image
- Set container name
- Pull the docker image
- Configure the MongoDB instance
- Set the local data directory
- Set the network parameters
- Run the MongoDB container
- Test connection
- Inspect the container
- See the container logs
- Kill the container
- Remove the container
- Remove the data directory
- References
IMAGE=mongo
TAG=4.4.3-bionic
NAME=mongodb
docker pull $IMAGE:$TAG
Contents of the .env file.
MONGO_INITDB_ROOT_USERNAME=user
MONGO_INITDB_ROOT_PASSWORD=topsecret
LOCAL_DATA_DIR=`pwd`/data
INTERFACE=127.0.0.1
PORT=27017
docker run -d --name $NAME --env-file .env -p $INTERFACE:$PORT:27017 \
-v "$LOCAL_DATA_DIR:/data" $IMAGE:$TAG
docker run --rm --link $NAME -it $IMAGE:$TAG \
mongo --host $NAME \
-u user \
-p topsecret \
--authenticationDatabase admin \
some-db
db.getName();
docker inspect $NAME
docker logs $NAME
docker kill $NAME
docker rm $NAME
rm -rf data