Skip to content

Instantly share code, notes, and snippets.

@myriaglot
Created July 27, 2026 12:18
Show Gist options
  • Select an option

  • Save myriaglot/3bfce3ed8e131aa678f9c28ce45f5bab to your computer and use it in GitHub Desktop.

Select an option

Save myriaglot/3bfce3ed8e131aa678f9c28ce45f5bab to your computer and use it in GitHub Desktop.
Debugging DigitalOcean MongoDB Connectivity in Podman vs. Podman-Compose

Improved Prompt

"My app connects to DigitalOcean Managed MongoDB via podman run, but fails via podman-compose. What networking, DNS, or Podman rootless differences cause this, and how do I fix it?"


The Issue Explained Simply

DigitalOcean uses an IP whitelist ("Trusted Sources").

  • podman run uses your host's network directly, so DigitalOcean sees your normal, whitelisted IP.
  • podman-compose creates an isolated network bridge using a proxy (slirp4netns/pasta). This proxy can alter or misroute outbound traffic, causing DigitalOcean to see an unauthorized request and block it.

Mongoose Test Program

1. package.json

{
  "name": "mongo-test",
  "version": "1.0.0",
  "main": "test.js",
  "dependencies": {
    "mongoose": "^8.0.0"
  }
}

2. test.js

const mongoose = require('mongoose');
const uri = process.env.MONGO_URI;

if (!uri) {
  console.error('❌ ERROR: MONGO_URI missing!');
  process.exit(1);
}

console.log('πŸ”„ Connecting to DigitalOcean MongoDB...');

mongoose.connect(uri)
  .then(() => {
    console.log('βœ… SUCCESS: Connected!');
    process.exit(0);
  })
  .catch((err) => {
    console.error('❌ FAILED:', err.message);
    process.exit(1);
  });

Run Test via podman exec

# 1. Start compose stack
podman-compose up -d

# 2. Install dependencies inside container
podman exec -it <container_name> sh -c "apk add --no-upgrade nodejs npm || apt-get update && apt-get install -y nodejs npm"
podman exec -it <container_name> npm install mongoose

# 3. Copy script into container
podman cp test.js <container_name>:/test.js

# 4. Run test script using container's MONGO_URI
podman exec -it <container_name> node /test.js
  • βœ… SUCCESS = Network/IP is working. Check app code or variable typos.
  • Timeout / Hang = DigitalOcean IP whitelist is blocking podman-compose traffic.
  • ENOTFOUND = podman-compose network DNS failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment