This is a mongo db docker image and container example configuration, you can use cli and directly up the mongo container or use the docker compose file and up the mongo container
(when you use docker compose, the container will always restarts whenever system starts [we have configured like that])
> docker-compose up -d
> docker-compose up -d --build
> docker volume create mongoChatAppData
when we create a volume and save the data in it, then if you delete your containers but not remove volumes, all your data will be safe
> docker network create my_network
Crating a network is optional
> sudo docker run -d \
--name mongoContainer \
-p 27017:27017 \
--network my_network \
-v mongoChatAppData:/data/db \
mongo:latest
> docker exec -it mongoContainer bash
> docker build -t mongo_image .
> docker run --rm -d -p 25000:27017 --name mongoContainer mongo_image
here we're not using any volume or network
we have changed the bindIp from localhost(127.0.0.1) to any using 0.0.0.0 so anyone can connect to this MongoDB server -> security issue
If you want to allow only a specific Ip then add that Ip's in the bindIp and remove 0.0.0.0 like 127.0.0.1, 192.153.0.17
> mongosh --host yourHostIp -port 27017
END