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

Detect if sudo is needed for docker commands #86

Closed
wants to merge 1 commit into from
Closed

Detect if sudo is needed for docker commands #86

wants to merge 1 commit into from

Conversation

SuperSandro2000
Copy link
Contributor

@SuperSandro2000 SuperSandro2000 commented Apr 7, 2020

With this I can just run the make docker-build even when I am not in the docker group and I just get prompted for my sudo password.

@maximbaz
Copy link
Collaborator

maximbaz commented Apr 7, 2020

This seems like an overkill to do in each and every Dockerfile in the world.... Have you considered making a wrapper for yourself instead that will ask for sudo password?

For example, put the script below in /usr/local/bin/ (assuming it is in your PATH and is defined earlier than /usr/bin/):

#!/bin/sh

sudo -E /usr/bin/docker "$@"

@SuperSandro2000
Copy link
Contributor Author

Than autocomplete and the help would need sudo rights, too which I do not want. Also I don't want to modify my system docker behavior. I could put my script from .bash_aliases to ~/.local/bin which then also would work in make. Still does would help all people which are logged into some docker registry with their normal user and want to build this image.

@mpolden
Copy link
Owner

mpolden commented Apr 7, 2020

This is too specific to your particular environment. If you want to replace the docker command with a variable (e.g. add DOCKER ?= docker at the top) which you can then override to whatever you want, I'm fine with that.

@SuperSandro2000
Copy link
Contributor Author

This is too specific to your particular environment.

In fact not really. It just detects if the current user is in the docker group in which case sudo wouldn't be needed and then it keeps all docker and docker-compose relevant ENVs and runs docker with sudo. Very very generic and should basically work everywhere without thinking about it for a second.

@SuperSandro2000
Copy link
Contributor Author

If you want to replace the docker command with a variable (e.g. add DOCKER ?= docker at the top) which you can then override to whatever you want, I'm fine with that.

Well, I ended up doing that in #89

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.

3 participants