- Docker MongoDB: use
mongo:9(MongoDB 9.0, the current stable release) and setMONGO_INITDB_ROOT_USERNAMEandMONGO_INITDB_ROOT_PASSWORD; without them the image requires no authentication. - Keep MongoDB data in a named volume at
/data/db. On Windows and macOS hosts the image documentation says a bind-mounted host folder will not work for MongoDB's data files. - Redis:
redis:8is Redis Open Source 8.10, which replaces Redis Stack and is licensed under a choice of RSALv2, SSPLv1 or AGPLv3. - The redis image turns protected mode off, so never publish 6379 to the internet without a password; bind it to
127.0.0.1for local work. - The official mongo-express image is deprecated with no supported tags; use MongoDB Compass or mongosh instead. For Redis, run
redis/redisinsighton port 5540.
Docker MongoDB: run the mongo image with a root user
There are two documented MongoDB images. The Docker Official Image mongo is the one most tutorials use; MongoDB's own manual describes mongodb/mongodb-community-server, which MongoDB maintains. Both run MongoDB Community Edition. On 8 October 2026 the mongo image tags 9, 9.0 and latest point to 9.0.2, and 8.3, 8.0 and 7.0 are also published. MongoDB lists 9.0 as the current stable release and recommends always installing the latest stable version.
By default the image's configuration requires no authentication, even for the administrative user. Setting both MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD creates a user with the root role in the admin authentication database and starts mongod with authentication enabled. As with the SQL images, these variables only apply to an empty data directory.
docker run -d --name mongo -p 127.0.0.1:27017:27017 -v mongodata:/data/db -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=<your-password> mongo:9docker exec -it mongo mongosh -u root -p <your-password> --authenticationDatabase adminInit scripts and configuration
On first start the image runs .sh and .js files in /docker-entrypoint-initdb.d in alphabetical order; .js files run in mongosh against MONGO_INITDB_DATABASE, or test if it is not set. Because MongoDB creates databases on first use, no database appears until a script inserts data. mongod options go after the image name (for example mongo:9 --profile 1), or in a configuration file passed with --config. MongoDB 5.0 and later images need a CPU with AVX support.
MongoDB Docker persistent storage
MongoDB writes its data files to /data/db inside the container, and the image also declares /data/configdb for config servers. Mount a named volume at /data/db, as in the command above, so the data outlives the container.
On Linux you can bind-mount a host folder (-v /my/own/datadir:/data/db). On Windows and macOS the image documentation warns that the file sharing between the host and the Linux container is not compatible with the memory-mapped files MongoDB uses, so a host folder cannot be used as the data directory; use a named volume instead. MongoDB's manual adds that MongoDB requires a filesystem that supports fsync() on directories. Docker's docker compose down -v deletes named volumes, so leave out -v unless you want to wipe the data.
Mongo Express is deprecated: what to use instead
Older compose files pair MongoDB with the mongo-express web interface. On 8 October 2026 Docker Hub marks that official image as deprecated due to maintainer inactivity, with no supported tags, and its documentation carries a security notice that the interface can be used to execute malicious JavaScript on the server and should only be used privately for development. A deprecated image no longer receives updates, so we have left it out of the compose file below.
The documented alternatives are:
- MongoDB Compass, MongoDB's desktop GUI, which is free, source available and runs on Windows, macOS and Linux. Connect it to
localhostport 27017 with the root user and theadminauthentication database. - mongosh in the container, as shown above, for queries and administration.
- Other MongoDB GUI clients; see best MongoDB GUI tools for a comparison.
Redis Docker setup: image, licence and persistence
The redis Docker Official Image tags 8 and latest point to Redis 8.10.2 on 8 October 2026, with 8.8, 8.6, 8.4, 8.2, 7.4, 7.2 and 6.2 also published. Two changes in Redis 8 matter for Docker users:
- Naming and Stack. Redis Community Edition is now called Redis Open Source, and Redis 8 in Redis Open Source replaces Redis Stack. Search, JSON, time series and probabilistic data structures are part of Redis 8, so the separate
redis/redis-stackandredis/redis-stack-serverimages, whose documentation covers Redis Stack 7.x, are no longer needed for new projects. - Licence. From Redis 8.0, Redis is available under your choice of RSALv2, SSPLv1 or AGPLv3. Redis 7.2.4 and earlier were BSD-licensed, and 7.4 used the dual RSALv2 or SSPLv1 licence. Check the licence fits your use before shipping Redis inside a product.
Security. For easier container networking the image turns Redis protected mode off. If you publish the port beyond your host, Redis is open to anyone without a password, so bind it to 127.0.0.1 and set a password. Redis's security documentation describes requirepass as the legacy authentication method; ACL users are the fuller option.
Persistence. The image documentation shows persistence switched on with redis-server --save 60 1, which saves a snapshot every 60 seconds if at least one write happened. Redis offers two mechanisms: RDB writes point-in-time snapshots at intervals; AOF logs every write and replays it at startup; the two can be combined. With persistence on, files are written to the /data volume.
docker run -d --name redis -p 127.0.0.1:6379:6379 -v redisdata:/data redis:8 redis-server --save 60 1 --loglevel warning --requirepass <your-password>docker exec -it redis redis-cliRedis Insight in Docker
Redis Insight is Redis's GUI. Redis documents running it as redis/redisinsight:latest on port 5540, with a volume at /data if you want its settings to persist. If the volume gives a permission error, the documentation says the user with ID 1000 needs access to it. Browse to http://localhost:5540, then add your Redis database: from the Compose stack below, use host redis and port 6379, because services reach each other by service name. A health endpoint is available at http://localhost:5540/api/health/.
The older redis/redis-stack image bundled Redis Insight on port 8001; with Redis 8, run Redis and Redis Insight as two containers instead.
docker run -d --name redisinsight -p 5540:5540 -v redisinsight:/data redis/redisinsight:latestOne compose.yaml for MongoDB, Redis and Redis Insight
This file runs all three for local development. Ports are published on 127.0.0.1 only, passwords come from a .env file, and every service has a named volume. Run docker compose up -d in the folder, then connect Compass to localhost:27017 and Redis Insight (at http://localhost:5540) to redis:6379.
services:
mongo:
image: mongo:9
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD:?set MONGO_ROOT_PASSWORD in .env}
ports:
- "127.0.0.1:27017:27017"
volumes:
- mongodata:/data/db
redis:
image: redis:8
restart: unless-stopped
command: redis-server --save 60 1 --appendonly yes --requirepass ${REDIS_PASSWORD:?set REDIS_PASSWORD in .env}
ports:
- "127.0.0.1:6379:6379"
volumes:
- redisdata:/data
redisinsight:
image: redis/redisinsight:latest
restart: unless-stopped
ports:
- "127.0.0.1:5540:5540"
volumes:
- redisinsight:/data
depends_on:
- redis
volumes:
mongodata:
redisdata:
redisinsight:MONGO_ROOT_PASSWORD=<your-mongo-password>
REDIS_PASSWORD=<your-redis-password>Backups, troubleshooting and MongoDB Docker on AWS
MongoDB backups. mongodump is in the mongo image and creates a binary export; --archive writes a single file, and mongorestore --archive reads it back (--drop drops collections that are in the backup before restoring them). The commands below write the archive inside the container and copy it to the host. For Redis, the RDB snapshot and AOF files in the /data volume are the persistence files.
Common problems. A MongoDB container that exits at once on older hardware may lack AVX support. An authentication failure from a client usually means the admin authentication database was not specified. If credentials changed but the volume is old, the original user still applies. A Redis client that gets an authentication error needs the password you set with --requirepass.
On AWS. The images are ordinary Linux container images, so they also run on an Amazon EC2 instance with Docker installed; the volume, password and port advice above applies unchanged, and the database port should stay closed to the internet. For production, MongoDB's manual recommends the MongoDB Enterprise Docker image together with the MongoDB Enterprise Kubernetes Operator rather than the community image. Many teams use a managed service instead; see MongoDB hosting and managed Redis for the options.
docker exec mongo sh -c 'mongodump --username root --password "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin --archive=/tmp/mongo.archive'
docker cp mongo:/tmp/mongo.archive ./mongo.archiveFrequently asked questions
Which MongoDB image should I use, mongo or mongodb/mongodb-community-server?
Both run MongoDB Community Edition. mongo is the Docker Official Image with the init variables and scripts described here; mongodb/mongodb-community-server is maintained by MongoDB and is the one in MongoDB's own install guide. Pick one and pin a major version tag.
Is Redis still open source?
From Redis 8.0, Redis is offered under a choice of three licences: RSALv2, SSPLv1 or AGPLv3. Redis now calls the free distribution Redis Open Source.
Should I still use the redis/redis-stack image?
Not for new projects. Redis states that Redis 8.0 deprecates previous Redis and Redis Stack versions and that the search, JSON, time series and probabilistic modules are now part of Redis. Use redis:8 plus redis/redisinsight.
How do I get MongoDB Docker persistent storage on Windows?
Use a named Docker volume mounted at /data/db. The mongo image documentation says a Windows or macOS host folder cannot be used as MongoDB's data directory with the Linux images; Windows-based mongo images are also published as an alternative.
Why can my app not reach Redis or MongoDB on localhost?
Inside a container, localhost is that container. In Compose, use the service name (mongo or redis) as the host. From your own machine, use localhost with the published port.
Sources
- mongo Docker Official Image documentation (docker-library/docs)
- MongoDB manual: Install MongoDB Community with Docker
- MongoDB manual: Release Notes
- Docker Hub: mongo-express (deprecation notice)
- mongo-express image documentation (docker-library/docs)
- MongoDB Compass documentation
- MongoDB Database Tools: mongodump
- MongoDB Database Tools: mongorestore
- redis Docker Official Image documentation (docker-library/docs)
- Redis docs: Run Redis Open Source on Docker
- Redis docs: Redis Open Source 8.0 release notes
- Redis docs: Redis Open Source
- Redis docs: Run Redis Stack on Docker (archived, 7.x)
- Redis docs: Install Redis Insight on Docker
- Redis docs: Redis persistence
- Redis docs: Redis security
- Docker docs: Publishing and exposing ports
- Docker docs: Networking in Compose
Checked 8 October 2026.
How we research guides: our editorial method. We link only to official downloads and never host installers.