docker error: /var/run/docker.sock: no such file or directory
Asked Answered
H

14

96

I am new to docker. I have a shell script that loads data into impala and I want a docker file that runs builds an image and run the container. I am on mac, installed boot2docker and have the DOCKER_HOST env set up.

bash-3.2$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.15.3-tinycore64
Debug mode (server): true
Debug mode (client): false
Fds: 10
Goroutines: 10
EventsListeners: 0
Init Path: /usr/local/bin/docker
Sockets: [unix:///var/run/docker.sock tcp://0.0.0.0:2375]

I am trying to just installed a pre-built image using:

sudo docker pull busybox

I get this error:

sudo docker pull busybox 2014/08/18 17:56:19 Post http:///var/run/docker.sock/images/create?fromImage=busybox&tag=: dial unix /var/run/docker.sock: no such file or directory

Is something wrong with my docker setup?

When I do a docker pull busybox, It pulls the image and download is complete.

bash-3.2$ docker pull busybox
Pulling repository busybox
a9eb17255234: Download complete 
fd5373b3d938: Download complete 
d200959a3e91: Download complete 
37fca75d01ff: Download complete 
511136ea3c5a: Download complete 
42eed7f1bf2a: Download complete 
c120b7cab0b0: Download complete 
f06b02872d52: Download complete 
120e218dd395: Download complete 
1f5049b3536e: Download complete 
bash-3.2$ docker run busybox /bin/echo Hello Doctor
Hello Doctor

Am I missing something?

Handgrip answered 18/8, 2014 at 22:4 Comment(3)
I was having same problem. I rebooted my laptop. so its started working for me. (see docs.docker.com/installation/ubuntulinux) They have also mentioned to restart computer.Winer
worked for me when the I connected to internet ,I have no idea why it happened though :(Bedspring
@Winer your solution worked bestDulcedulcea
E
89

You don't need to run any docker commands as sudo when you're using boot2docker as every command passed into the boot2docker VM runs as root by default.

You're seeing the error when you're running as sudo because sudo doesn't have the DOCKER_HOST env set, only your user does.

You can confirm this by doing a:

$ env

Then a

$ sudo env

And looking for DOCKER_HOST in each output.

As for having a docker file that runs your script, something like this might work for you:

Dockerfile

FROM busybox

# Copy your script into the docker image
ADD /path/to/your/script.sh /usr/local/bin/script.sh

# Run your script
CMD /usr/local/bin/script.sh

Then you can run:

docker build -t your-image-name:your-tag .

This will build your docker image, which you can see by doing a:

docker images

Then, to run your container, you can do a:

docker run your-image-name:your-tag

This run command will start a container from the image you created with your Dockerfile and your build command and then it will finish once your script.sh has finished executing.

Echo answered 18/8, 2014 at 22:25 Comment(5)
Sorry about my ignorance but I dont think I have succeeded in building. "docker images": gives 2014/08/19 11:11:45 Get http:///var/run/docker.sock/v1.13/images/json: dial unix /var/run/docker.sock: no such file or directory. Should the docker be placed in the home directory and can it be named with any name? Is it the same as "image-name"?Handgrip
Can you paste the command you're using to build the docker image? It sounds like you're still using sudo on your OSX machine when you shouldn't be.Echo
$ docker build -t /Users/ig/Documents/tests/hellodocker . 2014/08/19 11:18:09 Invalid namespace name (), only [a-z0-9_] are allowed, size between 4 and 30; and hellodocker has just the contents of the dockerfile you gave. thanks a lot.Handgrip
Yeah you're trying to tag your docker image with a file path - try something else after -t like your-image-name:a-tag.Echo
Could you give me the command line, pls. I'm messing up something. my docker file is hellodocker and the path is given above.Handgrip
B
45

You can quickly setup your environment using shellinit

At your command prompt execute:

$(boot2docker shellinit)  

That will populate and export the environment variables and initialize other features.

Bethanie answered 7/11, 2014 at 18:43 Comment(0)
U
26

On my MAC when I start boot2docker-vm on the terminal using

boot2docker start

I see the following

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_CERT_PATH=<my things>
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://<ip>:2376

After setting these environment variables I was able to run the build without the problem.

Update [2016-04-28] If you are using a the recent versions of docker you can do

eval $(docker-machine env) will set the environment

(docker-machine env will print the export statements)

Unmeaning answered 1/11, 2014 at 13:31 Comment(1)
You can also add these to your terminal profile to save time. The vm will inform you that they're already set.Bouilli
M
26

docker pull will fail if docker service is not running. Make sure it is running by

:~$ ps aux | grep docker
root     18745  1.7  0.9 284104 13976 ?   Ssl  21:19   0:01 /usr/bin/docker -d

If it is not running, you can start it by

sudo service docker start

For Ubuntu 15 and above use

sudo systemctl start docker

Misrepresent answered 9/4, 2015 at 15:54 Comment(0)
S
17

I also got this error. Though, I did not use boot2docker but just installed "plain" docker on Ubuntu (see https://docs.docker.com/installation/ubuntulinux/).

I got the error ("dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?") because the docker daemon was not running, yet.

On Ubuntu, you need to start the service:

sudo service docker start

See also http://blog.arungupta.me/resolve-dial-unix-docker-sock-error-techtip64

Sprawl answered 28/3, 2015 at 11:42 Comment(0)
C
9

For boot2docker on Windows, after seeing:

FATA[0000] Get http:///var/run/docker.sock/v1.18/version: 
dial unix /var/run/docker.sock: no such file or directory.  
Are you trying to connect to a TLS-enabled daemon without TLS?

All I did was:

boot2docker start
boot2docker shellinit

That generated:

export DOCKER_CERT_PATH=C:\Users\vonc\.boot2docker\certs\boot2docker-vm
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://192.168.59.103:2376

Finally:

boot2docker ssh

And docker works again

Country answered 26/5, 2015 at 18:35 Comment(0)
T
6

In Linux, first of all execute sudo service docker start in terminal.

Tumefy answered 19/7, 2015 at 9:51 Comment(0)
I
5

If you're using CentOS 7, and you've installed Docker via yum, don't forget to run:

$ sudo systemctl start docker
$ sudo systemctl enable docker

This will start the server, as well as re-start it automatically on boot.

Intellectualism answered 16/9, 2015 at 18:56 Comment(0)
D
4

To setup your environment and to keep it for the future sessions you can do:

echo 'export DOCKER_HOST="tcp://$(boot2docker ip 2>/dev/null):2375";' >> ~/.bashrc

Then: source ~/.bashrc

And your environment will be setup in every session

Dittany answered 3/12, 2014 at 21:10 Comment(0)
A
3

In case anyone stumbles on this: for Docker Desktop on Mac you have to enable this option in settings enter image description here

Autism answered 7/8, 2023 at 7:36 Comment(0)
T
0

The first /var/run/docker.sock refers to the same path in your boot2docker virtual machine. Correcly write for windows /var/run/docker.sock

Thermoluminescent answered 19/12, 2016 at 5:44 Comment(1)
Can you add some more explanation here? Also, I think the user is on a mac.Herries
B
0

You, maybe the not the OP, but someone may have a directory called /var/run/docker.sock/ already due to how many times you hack and slash to get things right with docker (especially noobs). Delete that directory and try again.

This helped me on my way to getting it to work on Centos 7.

Bluebird answered 13/1, 2017 at 13:13 Comment(0)
S
0

I have installed the docker using offline method and post server restart docker is not running. So, I executed the below command it worked for me!

/usr/bin/dockerd > /dev/null
Speculum answered 2/3, 2022 at 18:34 Comment(0)
D
0

run the following commands, OS = CentOS / RHLE / Amazon Linux, etc.

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
chmod 777 /var/run/docker.sock
Dispatch answered 10/2, 2023 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.