Skip to content
Guide · Run databases in Docker

MongoDB & Redis in Docker: Quick Setup Guide

MongoDB and Redis both have official images on Docker Hub, and a small compose.yaml can run them side by side with Redis Insight as a browser GUI. This guide covers the documented setup for MongoDB 9.0 and Redis Open Source 8: which images and tags to use, enabling authentication, persistent storage, the current status of Mongo Express and Redis Stack, backups, and notes for running the same containers on AWS.

Steps checked 8 October 2026 against the official documentation for each product. Versions covered: MongoDB 9.0.2 (mongo:9 image), Redis Open Source 8.10.2 (redis:8 image), Redis Insight (redis/redisinsight:latest). Next review due April 2027. Installers, versions and download pages change; follow the official page if a step differs.
Short answer
  • Docker MongoDB: use mongo:9 (MongoDB 9.0, the current stable release) and set MONGO_INITDB_ROOT_USERNAME and MONGO_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:8 is 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.1 for local work.
  • The official mongo-express image is deprecated with no supported tags; use MongoDB Compass or mongosh instead. For Redis, run redis/redisinsight on port 5540.
How we know: Research-based: tags, environment variables, paths, licences and image status were checked against the official mongo, mongo-express and redis image documentation, MongoDB's and Redis's documentation and Docker's documentation on 8 October 2026. We have not run these commands for this guide; if your image version differs, follow the official page.

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.

Start MongoDB 9.0 with a root user and a named volume
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:9
Open mongosh inside the container against the admin authentication database
docker exec -it mongo mongosh -u root -p <your-password> --authenticationDatabase admin

Init 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 localhost port 27017 with the root user and the admin authentication 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-stack and redis/redis-stack-server images, 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.

Start Redis 8 with RDB snapshots every 60 seconds (if at least one write) and a named 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>
Open redis-cli inside the container
docker exec -it redis redis-cli

Redis 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.

Run Redis Insight on its own, with persisted settings
docker run -d --name redisinsight -p 5540:5540 -v redisinsight:/data redis/redisinsight:latest

One 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.

compose.yaml: MongoDB 9.0, Redis 8 and Redis Insight
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:
.env in the same folder
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.

Dump all MongoDB databases to one archive and copy it out
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.archive

Frequently 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

Checked 8 October 2026.

How we research guides: our editorial method. We link only to official downloads and never host installers.

Database installed?

Write your first queries with the free beginner course, then practise on real problems.