🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
🪟 Windows TippsHow to remove a Drop-Down list in Excel(13.09.2026 um 01:50 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
🪟 Windows TippsHow to remove a Drop-Down list in Excel(13.09.2026 um 01:50 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

How to Run MongoDB in Docker

↗ Quelle (dev.to)
🗣️ Stimme:

Running MongoDB in Docker is an excellent way to set up a database without installing it directly on your local machine. This guide will show you how to use Docker to quickly spin up a MongoDB instance using the latest mongo:8 image.



Prerequisites



Before you begin, make sure you have the following:




  1. Docker installed on your system (Docker Desktop for Windows/Mac, or Docker CLI for Linux).


  2. Basic understanding of how Docker works.




*Step 1: Pull the MongoDB Image

*



Docker Hub provides an official MongoDB image. To ensure you’re using the latest MongoDB 8 version, pull the mongo:8 image with this command:



docker pull mongo:8



This command fetches the latest MongoDB 8 image from Docker Hub and makes it available locally.



Step 2: Run MongoDB in a Container



Run a container with the mongo:8 image using the following command:



docker run -d \

--name mongodb-container \

-p 27017:27017 \

-e MONGO_INITDB_ROOT_USERNAME=admin \

-e MONGO_INITDB_ROOT_PASSWORD=adminpassword \

mongo:8



Breaking Down the Command:



• docker run -d: Starts the container in detached mode.



• --name mongodb-container: Assigns a name to the container (you can choose any name).



• -p 27017:27017: Maps MongoDB’s default port 27017 to your local machine, making it accessible.



•-e: Sets environment variables to configure the database:



• MONGO_INITDB_ROOT_USERNAME: Sets the root username (e.g., admin).



• MONGO_INITDB_ROOT_PASSWORD: Sets the root password (e.g., adminpassword).



• mongo:8:

Specifies the image to use.



Step 3: Verify the Container is Running



Check if the container is running with the following command:



docker ps



You should see something like this:



CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES

abcdef123456 mongo:8 "docker-entry..." Up 5 minutes 0.0.0.0:27017->27017/tcp mongodb-container



This confirms MongoDB is running and accessible on



localhost:27017



Step 4: Connect to MongoDB



Using the Mongo Shell:



If you have the MongoDB client installed locally, connect to the running container with:



mongo --host localhost --port 27017 -u admin -p adminpassword



Using a GUI:



Tools like MongoDB Compass or Robo 3T make it easy to interact with your database visually. Just connect to localhost:27017 and use the credentials:



• Username: admin

• Password: adminpassword



Step 5: Persist Data with Volumes (Optional)



By default, Docker containers are ephemeral, meaning all data will be lost when the container is removed. To persist MongoDB data, map a local directory to the container’s data directory.



Run the container with a volume:



docker run -d \

--name mongodb-container \

-p 27017:27017 \

-e MONGO_INITDB_ROOT_USERNAME=admin \

-e MONGO_INITDB_ROOT_PASSWORD=adminpassword \

-v /path/to/your/local/data:/data/db \

mongo:8



What Changed?



• -v /path/to/your/local/data:/data/db : Maps a local directory (/path/to/your/local/data) to MongoDB’s data directory (/data/db), ensuring data persists even after the container is removed.



Step 6: Stop and Remove the Container



When you’re done, you can stop the MongoDB container:



docker stop mongodb-container



Conclusion



Using Docker to run MongoDB is a simple and efficient way to manage your database. It saves time, ensures consistency, and keeps your local machine clean from unnecessary installations. By following these steps, you can set up a MongoDB instance with Docker in just a few minutes

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
ChatGPT automatically logged out [Fix]
1 Quelle
How to remove a Drop-Down list in Excel
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Run MongoDB in Docker

Thematisch verwandte Begriffe: MongoDB, Docker · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...