Mongo DB in Docker
22 September 2020
Updated: 03 September 2023
Considerations
To run MongDB in a Docker Container there are a few things to take note of:
- You may need to configure auth
- Volume storage to be set up
From Terminal
To run a Docker container using a single command in the terminal you can run the following command:
1docker run -d -p 27017:27017
You can also specify additional information like the volumes you would like to use using flags when running:
1docker run -d -p 27017:27017
From Compose
More info can be found here
You can also run a MongoDB Container with Compose which may be a bit easier:
docker-compose.yml
1version: '3.3'2
3services:4 # mongonode0:270175 mongo0:6 image: mongo7 hostname: mongo08 container_name: mongo09 restart: always10 ports:11 - '37000:27017'12 volumes:13 - ./mongo0-data:/data/db14 environment:15 MONGO_INITDB_ROOT_USERNAME: root16 MONGO_INITDB_ROOT_PASSWORD: password