VOOZH about

URL: https://thenewstack.io/container-security-manage-secrets-with-portainer/

⇱ Container Security: Manage Secrets with Portainer - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-05-29 03:00:32
Container Security: Manage Secrets with Portainer
tutorial,
Containers / Security

Container Security: Manage Secrets with Portainer

If you want to add secrets and make them available to your Docker services and full-stack apps, Portainer is a great tool to make this process incredibly easy.
May 29th, 2022 3:00am by Jack Wallen
👁 Featued image for: Container Security: Manage Secrets with Portainer

Portainer is one of the most powerful Docker (and Docker Swarm) managers on the market. With this tool, you can create and manage every aspect of your container deployments, including the management of services, networks, images, registries, volumes, configs, stacks, orchestration, and even secrets.

That’s right, you can even manage secrets for your containers.

What’s the big deal with secrets? Well, if you haven’t heard, containers can be stubbornly insecure. Given how many moving parts you’ll find in a deployment, it can be all too easy to develop and deploy something in such a way that it’s easy for ne’er do wells to gain access to a running container or service, only to then leverage the passwords, certificates, and keys they find within. With those secrets (i.e. passwords, certificates, and keys), they can use them to gain access to your services, APIs, accounts, and more.

You don’t want that. Trust me.

To avoid such a scenario, Docker makes it possible for developers to store their secrets outside the services in an encrypted form and then call connect containers to the secrets. This is a much better method of keeping sensitive information from prying eyes.

And, guess what? Portainer makes it easy to work with secrets. In fact, I’ve yet to come across an easier method of managing/using secrets. And I’m going to show you how to do just that.

Requisites

To work with secrets, you’ll need a running instance of Portainer (which I’ve explained how to deploy Portainer in “Deploy Portainer for Easier Container Management“). One caveat to this is that Portainer must be running on a Docker Swarm, otherwise, you won’t have access to the Secrets option. To find out how to deploy Docker in Swam mode, make sure to check out “Tutorial: Manage Docker Swarm with Portainer.”

With Portainer up and running, you are ready to create your first secret.

Creating a Secret

The first thing we’ll do is create a secret. Log into Portainer, select your Environment, and click Secrets from the left navigation (Figure 1):

👁 Figure 1: The Portainer main page in action.

Figure 1: The Portainer main page in action.

In the resulting window (Figure 2), click Add Secret:

👁 Figure 2: The Secrets management window in Portainer.

Figure 2: The Secrets management window in Portainer.

In the next window (Figure 3), give the secret a name, add the actual secret into the Secret field, and (if you’re using plain text secrets) make sure Encode secret is enabled:

👁 Figure 3: Adding a new secret in Portainer.

Figure 3: Adding a new secret in Portainer.

If you need to Enable access control to the secret, you can select either Administrators (default) or click Restricted and select the users you want to grant access to the new secret (Figure 4):

👁 Figure 4: Restricting access to a new secret to specific users.

Figure 4: Restricting access to a new secret to specific users.

After you’ve configured the secret exactly how you want it, click Create the secret and the configuration will be saved.

Using Your New Secret

Okay, let’s now use that new secret. To illustrate this, we’ll deploy a basic Redis service that uses the secret. Although this might not be the perfect illustration, it’s a simple way of showing how it’s done.

To create the service, click Services in the left sidebar and then click Add service. In the resulting window (Figure 5), first, fill out the basic information for the service:

👁 Figure 5: Adding a new service from within Portainer.

Figure 5: Adding a new service from within Portainer.

Fill out the following information:

  • Name – redis-secret-test
  • Image – redis:alpine

Scroll down until you see the Secrets tab (Figure 6):

👁 Figure 6: The Secrets tab is in the advanced configuration options

Figure 6: The Secrets tab is in the advanced configuration options

Click Add a secret and, from the drop-down (Figure 7), select the new secret you just created: 

👁 Figure 7: Selecting our SSH-KEY secret we just added to Portainer.

Figure 7: Selecting our SSH-KEY secret we just added to Portainer.

Finally, click Create the service and the service will deploy. You will then be taken back to the Service list, where you’ll see your new service has deployed. If you click on the redis-secret-test entry, you will see the secret has been successfully attached to the service (Figure 8):

👁 Figure 8: Our service has been deployed with the secret intact.

Figure 8: Our service has been deployed with the secret intact.

Should someone gain access to that service, they won’t be able to view the secret, because it’s been encrypted and cannot be viewed. In fact, even if someone gains access to your Portainer instance, they can view the secrets listing but cannot view the secret itself.

With the service deployed, you will also notice that a container has also been created. You will not, however, find a listing or even access to the secret from within the container listing.

Another thing to keep in mind is that you cannot delete a secret if it is being used by a running service. So, if you find a need to delete a secret, first delete the service, and then you can remove the secret.

Conclusion

If you want to add secrets and make them available to your Docker services and full-stack apps, Portainer is a great tool to make this process incredibly easy. I highly recommend you spin up Portainer in a development environment and practice creating and using secrets before you jump right into a production environment with this process. Remember, your containers have a lot of moving parts, so the last thing you want to do is add unencrypted secrets to make it easy for bad actors to hack your deployments.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker, Enable.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.