Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement using dockercfg from a file-like object #2040

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lieryan
Copy link

@lieryan lieryan commented May 26, 2018

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)

@GordonTheTurtle
Copy link

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" git@github.com: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.

@lieryan lieryan changed the title Using dockercfg from a file-like object Implement using dockercfg from a file-like object May 26, 2018
Signed-off-by: Lie Ryan <lie.1296@gmail.com>
Signed-off-by: Lie Ryan <lie.1296@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants