docker error: /var/run/docker.sock: no such file or directory
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 imageADD /path/to/your/script.sh /usr/local/bin/script.sh# Run your scriptCMD /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.
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.
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= export DOCKER_TLS_VERIFY=1 export DOCKER_HOST=tcp://: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)