Docker Setup Guide: MongoDB Postgress

 

🔧 Docker Setup Guide: MongoDB, pgAdmin4, and File Access Troubleshooting on Windows

🧭 Introduction

This article walks through the practical setup of mongo-express and pgAdmin4 using Docker on Windows. We'll troubleshoot common issues like port conflicts, file upload limitations, and Docker networking quirks, and show how to enable file access between your Windows filesystem and Docker containers.


⚙️ Prerequisites

  • Docker installed on Windows

  • Basic familiarity with Docker CLI and containers

  • Local SQL or backup files you'd like to use inside containers


🧱 Part 1: Setting up MongoDB and Mongo-Express in Docker

✅ 1. Start the MongoDB container

powershell
docker run -d --name mongo -p 27017:27017 mongo

✅ 2. Create a custom Docker network

powershell
docker network create mongo-network

✅ 3. Run mongo-express with custom credentials and port

Make sure port 8085 or 8086 is not already in use. You can check with:

powershell
docker ps

Then run:

powershell
docker run -d ` -p 8086:8081 ` --name mongo-express ` --network mongo-network ` -e ME_CONFIG_MONGODB_SERVER=mongo ` -e ME_CONFIG_BASICAUTH_USERNAME=mongo ` -e ME_CONFIG_BASICAUTH_PASSWORD=306090 ` mongo-express

Visit: http://localhost:8086

❌ Issue: Mongo Express Error — Command listDatabases requires authentication

If MongoDB has authentication enabled (e.g., with a root username/password), you must pass that into mongo-express:

powershell
-e ME_CONFIG_MONGODB_ADMINUSERNAME=your_user ` -e ME_CONFIG_MONGODB_ADMINPASSWORD=your_pass `

Otherwise, you’ll get the MongoServerError: Command listDatabases requires authentication.


🧱 Part 2: Running PostgreSQL and pgAdmin4

✅ 1. Start the PostgreSQL container

powershell
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres

✅ 2. Create a network (if not already created)

powershell
docker network create postgres-network

✅ 3. Start pgAdmin4 with port 8081

powershell
docker run -d ` -p 8081:80 ` --name pgadmin4 ` --network postgres-network ` -e PGADMIN_DEFAULT_EMAIL=admin@admin.com ` -e PGADMIN_DEFAULT_PASSWORD=306090 ` dpage/pgadmin4

Access: http://localhost:8081


❌ Problem: “Unable to connect to server: [Errno -3] Try again”

This usually means pgAdmin cannot resolve the hostname postgres.

✅ Fix:

Make sure both containers are on the same Docker network and use the container name postgres in pgAdmin connection settings (not localhost).

Check networks:

powershell
docker network inspect postgres-network

If containers already show up there, you’re good. If not, connect them manually:

powershell
docker network connect postgres-network pgadmin4 docker network connect postgres-network postgres

🗂️ Part 3: Enabling File Uploads in pgAdmin (Query Tool)

❌ Problem: “Click the folder icon — but it’s empty”

This happens because Docker containers can’t access Windows filesystem unless a volume is mounted.


✅ Option 1: Copy files directly into the container

powershell
docker cp "C:\Users\DELL\Documents\backup.sql" pgadmin4:/var/lib/pgadmin/storage/admin_admin.com/

Replace admin_admin.com with your actual user folder in pgAdmin storage.


✅ Option 2: Mount Windows folder into pgAdmin container

This is the preferred method if you want continuous access to local .sql or .backup files.

  1. Stop and remove existing pgAdmin container:

powershell
docker stop pgadmin4 docker rm pgadmin4
  1. Create a local folder for pgAdmin storage:

powershell
mkdir C:\Users\DELL\pgadmin_data
  1. Run pgAdmin with volume mount:

powershell
docker run -d ` -p 8081:80 ` --name pgadmin4 ` --network postgres-network ` -e PGADMIN_DEFAULT_EMAIL=admin@admin.com ` -e PGADMIN_DEFAULT_PASSWORD=306090 ` -v "C:\Users\DELL\pgadmin_data:/var/lib/pgadmin/storage/admin_admin.com/" ` dpage/pgadmin4

Now when you click the folder icon in the Query Tool or Restore dialog, you’ll see your .sql files.


🛠️ Additional Tips

  • Reset a container:
    If you need to start over, run:

    powershell
    docker stop <container> docker rm <container>
  • Check container logs:
    For debugging:

    powershell
    docker logs <container-name>
  • Use Docker Compose:
    For production or more complex setups, consider using a docker-compose.yml file.


✅ Conclusion

With proper port assignments, Docker networks, and mounted volumes, you can easily run database tools like mongo-express and pgAdmin4 locally with full access to your Windows files. This setup is lightweight and ideal for dev/test environments.

Comments