osx - Running docker as sudo

07
2014-07
  • Cris

    I installed boot2docker and the i run

    ./boot2docker start
     export DOCKER_HOST=tcp://localhost:4243
    

    so i started the tutorial from their docker site.

    I don't understand one thing:

    when i run

    sudo docker info
    ==>
    Get http:///var/run/docker.sock/v1.11/info: dial unix /var/run/docker.sock: no such file or directory
    

    however when i run without sudo just works

    MacCris:bin cristianc$ docker info
    Containers: 2
    Images: 10
    Storage Driver: aufs
     Root Dir: /mnt/sda1/var/lib/docker/aufs
     Dirs: 14
    Execution Driver: native-0.2
    Kernel Version: 3.14.1-tinycore64
    Debug mode (server): true
    Debug mode (client): false
    

    Any idea why running with sudo as in the tutorial does not work ? (at least for me)

    Thanks

  • Answers
  • Brian Hartsock

    The DOCKER_HOST environment variable isn't set. You can confirm this by doing:

    > env
    

    Then as sudo:

    > sudo env
    

    Without the DOCKER_HOST variable set, docker can't connect to the daemon.


  • Related Question

    osx - How to run a program as root without "sudo"?
  • UrEl

    I have a certain binary program on OS X that can only be run as root.

    I'm tired of prepending sudo each time I invoke it and typing the password, and would like it to automatically run as root when I invoke it regularly, without asking for a password.

    The program's owner is root and its group is wheel.

    I tried chmod ug+s to set the userid and groupid upon execution to root/wheel, but when I run the program without sudo it still complains that it can only run with sudo or as root.


  • Related Answers
  • KeithB

    Are you sure that the program you are trying to execute is actually a binary, and not a shell script. Most shells ignore suid scripts because they are really, really hard to do safely. An easy way to check is to use the file command on the program.

  • Walter

    A half solution to your problem:

    in the sudoers file, add the following:

    username ALL= NOPASSWD: /path/to/command
    

    Then from the command line, you can type:

    sudo command
    

    and it will run the command without asking for your password. This command will run as root.

    Note, you will need to replace username with you actual username.

  • NReilingh

    If you really can't invoke it as a daemon for whatever reason (this question would be relevant in that instance), this method can be hacked together, but it's pretty dirty, and not secure at all.

    The concept is to launch it with an AppleScript. You'll first need to know how to invoke the process from the command line (which if you're already using sudo, means you must be all set). You'll launch that process using the do shell script command, and instead of using sudo you'll write your credentials into the AppleScript:

    do shell script "/path/to/your/executable/here" user name "me" password "mypassword" with administrator privileges
    

    I reiterate the part about this being insecure: THIS MEANS YOUR ADMIN CREDS WILL BE STORED IN PLAIN TEXT. If at all possible, you should find some way to background this as a LaunchDaemon.

  • Journeyman Geek

    ON OSX suppose the program you have is locate in /usr/local/bin/YourProgramName ... To solve this issue the following command, To change the User Id/Group ID for file hierarchies rooted in the files instead of just the files themselves.

    sudo chown -R $(whoami) /usr/local/bin/

    ... then in Terminal invoke your programName, $YourProgramName

  • DTest

    You can do

    sudo tcsh
    

    which will put you in a root shell.

  • jet

    looks like the program itself checks if is running with ID=0

  • dag729

    You could sudo chown YOUR-USERNAME-HERE BINARY-NAME-HERE.

    Still, I totally agree with dmckee's comment.