在Play-with-Docker环境中找不到Docker Secrets目录('/run/secrets')求助
/run/secrets Hey there! Let's clear up the confusion around Docker Swarm secrets and that missing /run/secrets directory.
First off, a key point to remember: Docker Secrets aren't stored directly on your node's host filesystem. The /run/secrets directory only exists inside containers that have been granted access to the secret, not on the manager or worker nodes themselves.
Here's what's happening in your scenario:
- When you created the secret on manager1, it got stored in the Swarm's distributed Raft database (managed by the manager nodes). The host system won't have a
/run/secretsfolder because that's a container-specific mount point. - Bret Fisher's note about only the Manager Leader being able to get container names ties to Swarm cluster state management, but it doesn't change how secrets are accessed—you still need to mount the secret into a container to see the
/run/secretsdirectory.
How to actually see the /run/secrets directory
To access your secret and view the directory, you need to create a service (or a one-off container) that mounts the secret. For example:
- Create a Swarm service with the secret attached:
docker service create --name secret-test --secret your_secret_name nginx:alpine
- Exec into one of the service's containers to check the directory:
docker exec -it $(docker ps -q --filter name=secret-test) ls /run/secrets
Or for a quick, temporary check without creating a persistent service:
docker run --rm --secret your_secret_name alpine ls /run/secrets
Bonus: View the secret content directly on the manager node
If you just need to verify the secret's content without spinning up a container, use this command on any manager node:
docker secret inspect --format='{{.Spec.Data}}' your_secret_name | base64 -d
This decodes the base64-encoded secret stored in the Swarm database.
内容的提问来源于stack exchange,提问作者E235

