Hi there,
I’m writing a python based program that I want to be able to build Docker images using the docker
package.
However, I’m not entirely sure how to handle mounting build secrets since the API documentation for building doesn’t list an option for passing build secrets mount. It additionally says “This is not meant for passing secret values.” regarding the buildargs
parameter.
I did find that there is a client.secrets.create()
method, but that seems to store the secrets in a server, and I get an error regarding docker swarm:
docker.errors.APIError: 503 Server Error for http+docker://localhost/v1.46/secrets/create: Service Unavailable ("This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.")
I’m not trying to use swarm or store the secrets in the server anyways, as I just need to handle it locally as it builds without wanting to store it anywhere else.
The local setup that I’m trying to programmatically replicate:
My Dockerfile has these lines in it for mounting the required dotfile that contains the token, since the token is required to pip install private packages.
...
RUN --mount=type=secret,id=dotfile,dst=/root/.dotfile \
pip install -r requirements.txt
...
And then I build it with:
DOCKER_BUILDKIT=1 docker build . --secret id=dotfile,src=/home/me/.dotfile --target my-layer --tag program:1.0.0```
Is there then a way to run the above build command but via the python docker package without needing to store the secret in a server or use Docker swarm?