Docker secrets, which designated to create for storing the sensitive information like username, password, SSL certificates, and any secure files. Docker Secret is created and used widely in Docker Swarm and then extended to docker compose from v3. If anytime, you were worried about securing your sensitive data, Docker secret will be the one of the solutions for you.
Just imagine, we never want to store a configuration file with all of our passwords on our GitHub/any repository even in public or private. In this guide we will walk you through various aspects of setting up a using Docker secrets.
Before we head into steps, here is some introduction how it is used on docker swarm services. First, we create & add a secret to the swarm, and then we give our services access to the secrets they require. When the service is created (or updated), the secret is then mounted onto the container in the /run/secrets directory. Now your application has access to the secrets it requires.
Creating Secret
Just assume with your swarm already running or for test, please run “docker swarm init”, this initiate your docker swarm on the node. Now, you can use the docker secret create command to add a new secret to the swarm.
Here is a basic example:
echo "mypassword" | docker secret create mypass -
Now let’s use the “docker secret ls” command to confirm that our secret was added:
docker secret ls
should output something like this:
ID NAME CREATED UPDATED
rkxav7s9rvnc9d7ct6dhkrsyn mypass 3 minutes ago 3 minutes ago
Lets see what else we can do in Docker secret, before we heads to adding secret to service.
Inspect Docker Secret
You can use inspect command on Docker secret also, same as other docker commands
docker secret inspect secret_name
our case it will be “mypass”
Remove Docker Secret
You can remove the docker secret using following command
docker secret rm secret_name
Read how to add to service and docker compose on
https://foxutech.com/docker-secret-how-to-use-in-docker-swarm-and-compose/