Secret Volumes

Let us go ahead and see the demo for secret volumes where we will see how easy it is for our container to access secrets stored in a secret volume.
We are going to store a single secret into a volume and then our container will access the secret.
  1. First of all, login to your Azure account using the az login command and select your preferred subscription (if you have more than one).
    Azure

  2. Then, create a resource group and put it in your nearest datacenter.
    Azure

  3. Now, we will create a container group and use the az container create command, specifying the container group and the resource group it is in.
    We will use a very small Docker image i.e. alpine Linux that will help us to quickly start this up.
    The restart policy would be set to never and we are going to configure a secret that has the name PASSWORD and the value 'A very big secret!'
    We are also going to mount the secret at the /mnt/ketsecrets path. In that folder, there is going to be a file with the name PASSWORD and the content 'A very big secret!'.
    To check that this worked, we are just going to set a command line for our container to use cat to print out the contents of that file.
    Azure

  4. In a real-time application, this secret might contain something like a database connection string and so your code would go and read this file and use that when it's connecting to the database.
    Once we have created the container, it won't take very long to get running because the image which we took is very small and it will complete very quickly.
  5. We will use the az container logs command to see what is written to the log output. And we would be able to see the value of our secret.
    Azure
In a real-world scenario, however, you, of course, won't write secrets into a log file. This was just a demonstration of how easy it is to use these secret volumes so you can ensure that your secrets are never actually written to non-volatile storage.

Empty Volumes

However, there are some drawbacks of empty volumes,