SimpleACME
Sign inCreate account →
Software certificate guides

Replace Portainer's HTTPS certificate on 9443 without losing its data

Replace Portainer HTTPS certificates on 9443 using protected PEM mounts while preserving the data directory, environments, and a recovery path.

Portainer's HTTPS listener protects an interface that can administer powerful infrastructure. Replacing the default self-signed certificate should improve endpoint verification without changing the installation's database, Docker access, or managed environments. The safest plan separates the certificate mount from persistent Portainer data and preserves the current container definition before any recreation.

This guide assumes Portainer Community Edition on a supported Docker Standalone host, with native HTTPS on port 9443. It follows the current documented PEM certificate flags and uses folder bind mounts. Pin the exact supported image tag or digest already selected for your installation; the example does not prescribe an unreviewed upgrade. No live Portainer restart, certificate order, or account operation was performed while writing it.

Step 1: Capture the existing management installation

Record the running container's image, command arguments, published ports, network attachments, restart policy, and mounts. Identify exactly where /data persists. That folder contains the installation state you must retain. A certificate change should not create an empty /data directory and make Portainer appear freshly installed. Keep the prior Compose file or equivalent run definition beside your backup notes.

docker inspect portainer --format '{{.Config.Image}}'
docker inspect portainer --format '{{json .Mounts}}'
docker inspect portainer --format '{{json .Config.Cmd}}'
docker port portainer

Avoid dumping the entire environment into shared logs because other deployments may store credentials there. Preserve sensitive inventory privately. Back up Portainer using its supported backup process and your existing host-state procedure before recreating anything. A filesystem copy of a database that is actively changing may not be a consistent restore point; coordinate the backup method with the version and edition you run.

Confirm that you have direct administrative access to the Docker host independent of Portainer's browser UI. If the new certificate path is wrong, you need a way to restore the container definition without depending on the unavailable management panel. Record the hostname administrators use, such as containers.example.com, and verify its DNS and routing from their actual management network.

Port 9443 is the web interface and API in this example. Port 8000 is associated with Edge functionality and is optional when those features are unused. Port 9000 is legacy HTTP access, not a requirement for installing an HTTPS certificate. Do not expose extra ports merely because a broad copy-and-paste installation command contains them.

Step 2: Prepare a paid delegated challenge registration

Before requesting a certificate, create the matching domain registration in SimpleACME and add the assigned challenge CNAME at your DNS host. Enable the paid subscription so the update endpoint can accept the TXT updates used for validation. The preparation-only free domain is useful for arranging the CNAME, but it does not provide active challenge updates for issuance.

Use the public Certbot integration and the subscriber Certbot Docker guide if the renewal client also runs in Docker. Your ACME client obtains and renews the certificate from the CA, and your deployment workflow installs it into Portainer's certificate folder. SimpleACME supplies delegated DNS updates; it neither issues the certificate nor receives Portainer administrative access.

This arrangement suits a private administration endpoint because DNS validation does not require publishing an HTTP challenge server or making 9443 globally reachable. Keep the management network restricted. A trusted certificate removes a browser identity warning, but it does not replace strong Portainer accounts, appropriate environment access, host security, or a review of who can reach the Docker socket.

Choose whether the certificate will be managed through Portainer's UI or through explicit mounted files. Both are documented approaches, but mixing them without a source of truth complicates renewal. This guide uses files and startup flags so the deployment remains visible in the container definition. Document that choice before someone later uploads a different certificate through the UI.

Step 3: Stage regular PEM files in a dedicated folder

Prepare /opt/portainer/tls on the host, preserving your actual existing data folder separately. The certificate file must include the intermediate chain; a leaf-only certificate can work in one browser that cached an intermediate and fail for another client. Copy a validated fullchain.pem and matching privkey.pem as regular files with restrictive permissions.

sudo install -d -m 0700 /opt/portainer/tls
sudo install -m 0644 /secure/stage/fullchain.pem /opt/portainer/tls/fullchain.pem
sudo install -m 0600 /secure/stage/privkey.pem /opt/portainer/tls/privkey.pem
openssl x509 -in /opt/portainer/tls/fullchain.pem \
  -noout -issuer -dates -ext subjectAltName

Adjust ownership for your container's actual runtime identity. Do not assume every Portainer image or hardened runtime has the same file-access requirements. The mount should be read-only from the application when the external deployment workflow owns renewal. The host deployment identity can update the files without allowing the management application to rewrite them.

If you mount Certbot's live directory directly, understand that its entries commonly point into archive. Mounting only the visible leaf directory may leave broken symlinks inside the container. A controlled copy of validated regular files avoids that problem. Alternatively, follow Portainer's documented live-and-archive mount arrangement exactly and audit which certificate lineages become accessible.

Before activation, compare the public keys derived from the private key and leaf certificate. Keep the previous complete file generation in a protected rollback folder. Do not remove old certificate files until the new listener has been verified from a second machine. Files that are no longer current still contain sensitive private keys and need the same access controls.

Step 4: Recreate only the container definition that needs the flags

The Compose fragment below illustrates the intended file layout. Replace PORTAINER_PINNED_TAG with your existing reviewed tag or digest and preserve the real /data bind path. Do not run it as an unrelated second installation against the same data directory. Merge network settings, edition-specific options, and required Edge settings from the current definition.

services:
  portainer:
    image: portainer/portainer-ce:PORTAINER_PINNED_TAG
    container_name: portainer
    restart: unless-stopped
    ports:
      - "9443:9443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /opt/portainer/data:/data
      - /opt/portainer/tls:/certs:ro
    command:
      - --sslcert
      - /certs/fullchain.pem
      - --sslkey
      - /certs/privkey.pem

The socket mount grants significant control over the Docker host; it is an existing management requirement to review, not a side effect of TLS. This guide does not recommend sharing the socket with the renewal client. The renewal process needs to deliver files and trigger the approved restart, not run arbitrary Docker API calls as part of a DNS challenge.

Render and review Compose before applying it. Confirm that the image has not silently changed, the data path is the existing one, and no volume replacement or deletion is requested. Then recreate the service through the established Compose project. Watch logs and container state. A healthy process is only the first observation; it does not establish that your browser is receiving the new certificate.

docker compose config
docker compose up -d portainer
docker logs --since 5m portainer

Step 5: Verify browser access and API identity

Connect with the hostname and port administrators will use. Inspect the served certificate's SAN, chain, issuer, and expiry from an independent management workstation. Keep hostname verification enabled; an IP-based probe can produce a mismatch even when the hostname deployment is correct. The purpose is to verify the intended identity rather than find any URL that suppresses a warning.

openssl s_client -connect containers.example.com:9443 \
  -servername containers.example.com -verify_hostname containers.example.com \
  -verify_return_error </dev/null
curl --fail https://containers.example.com:9443/api/status

Open the UI, sign in, and confirm the expected environments and settings are still present. If the installation looks empty, stop and inspect the /data mount before creating a new administrator or re-enrolling environments. An accidental empty data path is a persistence error, not a certificate issue, and continuing setup can make the mistake harder to untangle.

Check existing API consumers that use the management endpoint. Some tools may have pinned the old self-signed leaf or disabled verification as a workaround. Replace accidental trust exceptions with the intended verified hostname and appropriate CA trust. Do not retain an insecure client option merely because the certificate is now publicly trusted; that option still prevents identity verification.

Step 6: Couple renewal to controlled activation and rollback

The renewal client producing new files is not enough. A deploy step must validate the chain and key, replace the mounted regular files, preserve ownership, and activate them through a documented restart or certificate-management workflow. Do not assume Portainer reloads mounted changes automatically without confirmation for your exact version. A controlled container restart is straightforward when its service interruption is planned.

Keep a lock around deployment so two renewal jobs cannot overwrite the same files concurrently. Record the certificate serial, deployment time, container image, and verification result without logging private key contents. Use one scheduler rather than leaving a host timer and a second container cron job competing over the same lineage. Duplicate issuance attempts can obscure failures and create unnecessary CA traffic.

If activation fails, restore the previous file generation and the previous command definition, then restart the same service with the preserved data mount. Verify access before proceeding. Do not delete the Portainer data folder or run a cleanup command against persistent state as a way to fix unreadable TLS files. Certificate rollback should leave users, environments, and authorization untouched.

Add an external expiry check to the live 9443 endpoint. Compare that result with the ACME client's local files so a broken copy or restart cannot remain unnoticed. SimpleACME's TXT activity timeline helps diagnose validation attempts, but it is not a record of Portainer deployment or a successful administrative session. Treat those as separate evidence in your runbook.

Keep environment connectivity in the acceptance check

After confirming the browser certificate, inspect one representative managed environment without changing it. The browser-to-Portainer HTTPS path is separate from Portainer's agent or Docker connection to that environment. A certificate replacement should preserve those connections. If an environment becomes unavailable, compare the recreated container's network attachments and command arguments with the saved definition before blaming the new public certificate. This is why the pre-change inventory includes more than the certificate flags alone.

Frequently asked questions

Do I need to open port 9000 for the replacement?

No. The example uses native HTTPS on 9443. Legacy HTTP access is a separate compatibility choice and should not be enabled solely to install a trusted certificate or complete DNS validation.

Why does Portainer say the certificate file is missing when it exists on the host?

Check the container path, mount, permissions, and symlink targets. A Certbot live symlink can point outside the mounted tree. Validate the path inside the running container's filesystem rather than relying only on a host directory listing.

Should the renewal client mount the Docker socket?

It does not need the socket for DNS validation or issuance. Use a narrowly controlled deployment action to activate the files. The Docker socket provides broad host-management capability and should not be granted simply for convenience.

Will replacing the container remove my environments?

Container recreation should preserve state when the exact existing /data persistence is retained. A wrong or empty bind path can make the installation appear new. Back up first and verify the effective mount before creating or changing accounts.

Official references

Portainer custom certificates documents PEM files, full chains, and startup flags. Portainer CE Docker installation explains listener ports and persistence. Follow the matching edition and supported image documentation for your deployment.

KEEP EXPLORING

A little more clarity.

ONE CNAME. A REPEATABLE WORKFLOW.

Your next certificate. A little less complicated.

Keep your DNS provider and your ACME client.
Prepare your domain before activating paid updates.

Create your account →Explore the integrations