I’m developing an application using the docker api with python3 using Docker Desktop for Mac (22.214.171.124). So far everything is working great but I need to provide passwords to the container using docker secrets. Swarm is running and I am able to create services. The problem I’m having is that the documentation indicates that to specify a secret the code needs to provide a list of “SecretReference” class objects. Where are SecretReference objects stored and how do I access them? I’m able to list and view the stored secrets in my swarm using the apis client.secrets.list() and client.secrets.get() but I have been unable to start the container service with any combination of values returned from these. I’ve looked at the documentation for the SecretReference class but it wasn’t helpful to me. How do I provide specific docker secrets to the service I’m creating?
Below is a brief code example that shows what I’m working with:
#!/usr/bin/env python3 import docker, getpass client = docker.from_env() my_pw = getpass.getpass(prompt='Password: ') client.secrets.create(name='new_pw', data=str.encode(my_pw)) client.services.create('ubuntu:latest', name='TestSvc', hostname='test_host', secrets=['new_pw'] )
If this is not an appropriate forum for this question then please let me know so that I can move my request.