Do you really know what you just downloaded?
Every day, we run docker pull as a reflex. But is the nginx:latest or ubuntu:22.04 image you just downloaded truly “clean”? Or has a hacker injected a backdoor and pushed it to Docker Hub with a similar-looking name to deceive users?
Two years ago, while managing a 50-node cluster for a Fintech project, an intern accidentally pulled an image from a personal repository for testing. Just 15 minutes later, monitoring alerts went off. Servers hit 100% CPU usage for background cryptomining. That mistake forced the entire team to stay up for two nights to audit the entire infrastructure.
To prevent such disasters, Docker Content Trust (DCT) is a mandatory solution. It ensures your system only runs images that have been digitally signed by someone you trust.
Enable DCT in 30 Seconds
By default, Docker allows all images. To tighten security, you only need to set a single environment variable on your Linux machine.
Step 1: Enable DCT Temporarily
export DOCKER_CONTENT_TRUST=1
Step 2: Verify Effectiveness
Try pulling an unsigned image (e.g., obscure personal images):
docker pull bitnami/not-signed-image:latest
Docker will block this command immediately with the message: “Error: remote trust data does not exist”. At this point, you can only download official images like library/nginx because they have valid signatures.
How Does DCT Work?
Think of DCT as a “digital notary.” It uses the Notary system to manage Public/Private Key pairs. When you push an image, Docker uses a private key to sign it. When someone else pulls it, Docker uses the public key to verify the signature.
If an image is modified by even a single bit, the signature will mismatch and the pull command will fail. There are two types of keys you should pay close attention to:
- Root Key: The master key to manage all permissions. Losing this key means losing total control over your trust data.
- Tagging Key: The key used to sign specific versions (tags) of an image.
Signing Your Own Images
In an enterprise environment, using images only from Docker Hub isn’t enough. You need to sign the images built by your team to ensure internal security.
1. Generate a Signing Key
First, generate a key pair on your local machine:
docker trust key generate my-signer-key
Docker will prompt for a passphrase. Keep it safe because the key file will be located at ~/.docker/trust/.
2. Add a Signer to the Repository
Suppose you use the repository myregistry.com/my-app. Grant signing permissions to a user:
docker trust signer add --key my-signer-key.pub my-signer-name myregistry.com/my-app
3. Push the Signed Image
When the DOCKER_CONTENT_TRUST=1 variable is enabled, the push command will automatically include the signature:
docker push myregistry.com/my-app:v1.0
From now on, any server with DCT enabled will fully trust this v1.0 version.
Deploying DCT in Production Environments
Manually typing the export command is easy to forget. To make it professional, I usually apply these two methods:
Permanent Configuration for Users: Add export DOCKER_CONTENT_TRUST=1 to the .bashrc file. This ensures all Docker operations for that user are always protected.
Apply to CI/CD Pipelines: In your deployment scripts (such as GitHub Actions or GitLab CI), set this environment variable before building/pushing. If the CI/CD server is compromised and an attacker tries to swap an image, the deployment process will fail immediately.
Practical Experience: Prevention is Better Than Cure
After several “stumbles,” I’ve learned three vital lessons when using Docker Trust:
- Backup the Root Key immediately: I once lost my Root Key after a fresh OS install, making it impossible to update signatures for old images. Keep the
~/.docker/trustfolder on an offline USB or a secure Vault. - Check Registry support: Not all registries are compatible with Notary. Docker Hub, Harbor, and Azure Container Registry (ACR) currently offer excellent support.
- Manage Base Images: Always use
FROMwith signed images. If your base layer is insecure, your entire image remains at risk.
Conclusion
Enabling Docker Content Trust might slow down your workflow by a few seconds to enter a password. However, that is a small price to pay compared to a system hit by ransomware or a customer data breach. If you manage critical systems, enable DCT today.

