Skip to content

Instantly share code, notes, and snippets.

@crazyoptimist
Last active April 9, 2024 23:20
Show Gist options
  • Save crazyoptimist/6b70fba82c5f02347579d825b61894e3 to your computer and use it in GitHub Desktop.
Save crazyoptimist/6b70fba82c5f02347579d825b61894e3 to your computer and use it in GitHub Desktop.
MongoDB Docker Deployment
name: mongodb
services:
mongodb:
container_name: mongo
image: mongo:7
volumes:
- mongodb_data:/data/db/
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: user
MONGO_INITDB_ROOT_PASSWORD: youmayneverguess
command: --quiet
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
restart: always
volumes:
mongodb_data:
@MatheusCoelho13
Copy link

thanks

@crazyoptimist
Copy link
Author

crazyoptimist commented Oct 1, 2020

Glad it helped!

@geekravi92
Copy link

This really worked like charm.

@crazyoptimist
Copy link
Author

Edit:
command: --quiet
Added it to shut up the too verbose docker compose log.

@crazyoptimist
Copy link
Author

Edit:
docker compose version 2 doesn't create the bind mounted dir automatically, so you will need to create the directory manually before running it:

mkdir db_data

Or just do not use bind mount if you don't have a reason for it.

@kevinadhiguna
Copy link

Hi, thank you for the YAML. May I know how to add timezone in MongoDB docker-compose ?

@crazyoptimist
Copy link
Author

crazyoptimist commented Feb 22, 2022

I think this link might help, I haven't tried it.

@kevinadhiguna
Copy link

Thanks, I got the timezone worked with :

...
environment: 
      MONGO_INITDB_ROOT_USERNAME: your_username
      MONGO_INITDB_ROOT_PASSWORD: your_strong_password
      TZ: "Europe/London"
...

List of timezone : Setting Local Time in Docker

@crazyoptimist
Copy link
Author

Great!

@crazyoptimist
Copy link
Author

crazyoptimist commented May 30, 2022

You can run mongo5+ only on a server of which CPU supports AVX.

@konstantinos2018
Copy link

Thank you

@crazyoptimist
Copy link
Author

Glad it helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment