How to run a MongoDB Docker container with exposed port

docker run -d  --name mongo-on-docker  -p 27888:27017 -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=secret mongo

This command allows you to start a new MongoDB container with exposed port so that you could access the instance from the outside world.

BETA Snippet explanation automatically generated by OpenAI:

Here is what the above code is doing:
1. Run a Docker container in the background and call it mongo-on-docker
2. Map the exposed port 27017 from the Docker container to port 27888 on the host
3. Set the environment variable MONGO_INITDB_ROOT_USERNAME to m

Snippet By Bobby Iliev

·

Created October 11th, 2021

·

Report Snippet