Running docker as sudo

12

6

I installed boot2docker and I ran:

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

I started a tutorial from the 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 it 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)?

Cris

Posted 2014-05-29T19:16:15.233

Reputation: 247

2This is because using sudo is clearing out your env. There is no need to use sudo here because you are connecting over the TCP interface – cpuguy83 – 2014-06-14T13:18:25.403

Answers

15

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.

Brian Hartsock

Posted 2014-05-29T19:16:15.233

Reputation: 166

3

Try:

sudo DOCKER_HOST=$DOCKER_HOST docker run

This way the required environment variable will be available with sudo.

lifeisfoo

Posted 2014-05-29T19:16:15.233

Reputation: 131

2

If you want the DOCKER_HOST variable from your profile to be available when you run docker command with sudo, then you can add the following line to sudoers file. Open with:

sudo visudo

Add:

Defaults        env_keep += "DOCKER_HOST"

surajz

Posted 2014-05-29T19:16:15.233

Reputation: 121

1

If you are using boot2docker, then go to /Application folder and run the command

$(boot2docker shellinit)

It will fix your DOCKER_HOST variable in environment.

smirnoffs

Posted 2014-05-29T19:16:15.233

Reputation: 111

0

Setting the environment variable DOCKER_HOST to tcp://192.168.59.103:2375 works for me.

Quickest way would be running this in your command line (for OSX/Unix/Linux machines):

export DOCKER_HOST=tcp://192.168.59.103:2375

Ardy Dedase

Posted 2014-05-29T19:16:15.233

Reputation: 101