docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Implement using dockercfg from a file-like object

Open lieryan opened this issue 6 years ago • 1 comments

This allows a number of different scenarios, for example, in situations where the user running docker-py does not have permission to read the .docker/config.json file. I encountered this situation when bind-mounting /root/.docker/config.json to a container that's running an application that uses docker-py as unprivileged user inside the container. A parent process running root can pass the file descriptor to the application:

#!/bin/sh
unusedfd=$(($(ls /dev/fd | sort -r | head -1)+1))
eval "DOCKER_CREDS_FD=${unusedfd} exec setpriv --reuid=app --regid=app $@ ${unusedfd}< config.json"

and the application can read it as such:

import os
dockercfg_fd = os.environ.get("DOCKER_CREDS_FD")
if dockercfg_fd is not None:
    dockercfg = os.fdopen(dockercfg_fd)
client = docker.from_env()
client.login("username", dockercfg)

lieryan avatar May 26 '18 02:05 lieryan

Please sign your commits following these rules: https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work The easiest way to do this is to amend the last commit:

$ git clone -b "master" [email protected]:lieryan/docker-py.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842362546256
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

GordonTheTurtle avatar May 26 '18 02:05 GordonTheTurtle