title: Setting up MongoDB in a docker container with Certbot's certificates
body: <p>How to I configure my MongoDB's ssl certificates?</p>
  <p>I want to host my MongoDB myself. I currently have a Linode container running, on it I've installed <code>certbot</code> and had it acquire certificates for the domain I want to use for my database.</p>
  <p>I'm using this <code>docker-compose.yml</code> file to deploy the MongoDB container:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '2'
  services:
    mongo:
      image: mongo:latest
      volumes:
         - ./db-data:/data/db
         - ./mongo-config:/data/config
         - ./certs:/data/certs
      ports:
         - &quot;0.0.0.0:27017:27017&quot;
      restart: always
      environment:
         - MONGO_INITDB_ROOT_USERNAME=exampleuser
         - MONGO_INITDB_ROOT_PASSWORD=examplepassword
     command: --config=/data/config/mongo.conf
  </code></pre>
  <blockquote>
  <p>and before someone mentions using nginx streams, certbot doesn't support them <a href="https://github.com/certbot/certbot/issues/5565" rel="nofollow noreferrer">(see issue)</a></p>
  </blockquote>
  <p>An my mongo config found at <code>./mongo-config/mongo.conf</code>:</p>
  <pre><code>net:
    port: 27017
    bindIp: 0.0.0.0
    ssl:
      mode: requireSSL
      PEMKeyFile: # This is where I need help, it would be in /data/certs from the container's perspective
  </code></pre>
  <p>Every guide mentions copying Certbot's files into a docker volume, so I setup ./certs to mount into <code>/data/certs</code> and copied them their. I've tried ever combination of every permutation of the files Certbot creates in the <code>PEMKeyFile</code> and the <code>CAFile</code> fields and nothing works. I'd get this error every time I tried:</p>
  <pre><code>error:0909006C:PEM routines:get_name:no start line
  </code></pre>
  <p>Guides I've already tried:</p>
  <ul>
  <li><a href="https://community.spiceworks.com/how_to/175272-configure-ssl-for-mongodb" rel="nofollow noreferrer">How to: Configure SSL For MongoDB</a></li>
  <li><a href="https://docs.mongodb.com/manual/tutorial/configure-ssl/" rel="nofollow noreferrer">Configure mongod and mongos for TLS/SSL</a></li>
  <li><a href="https://certbot.eff.org/docs/using.html#managing-certificates" rel="nofollow noreferrer">Certbot User Guide</a></li>
  <li><a href="https://gist.github.com/j0e1in/7621b23bc3ef8f942f66e2d8ac2aa2cf" rel="nofollow noreferrer">Setup Mongo 3.6 TSL/SSL with Letsencrypt</a> | this one mentioned that I have to download a certificate that expires TODAY (sept 30, 2021)</li>
  <li><a href="https://sebworks.com/securing-mongodb-tls-auth-letsencrypt/" rel="nofollow noreferrer">Securing MongoDB with TLS, Authentication and LetsEncrypt</a></li>
  </ul>
  <p>Related: <a href="https://stackoverflow.com/questions/50822387/letsencrypt-ssl-certificate-validation-failed-with-mongodb">LetsEncrypt SSL Certificate Validation Failed with MongoDB</a></p>