Because /var/run/docker.sock
is not directly available on a machine running boot2docker
.
docker build -t shared-docker-env .
docker run -ti --rm -v ~/.boot2docker/certs/boot2docker-vm:/root/.docker -v $(which docker):/usr/bin/docker -e DOCKER_HOST=$DOCKER_HOST shared-docker-env
-v ~/.boot2docker/certs/boot2docker-vm:/root/.docker
injects your boot2docker TLS certificates;-v $(which docker):/usr/bin/docker
injects the docker client in the container;-e DOCKER_HOST=$DOCKER_HOST
shares thedocker
daemon HTTP URL (eg:tcp://192.168.59.103:2376
) – enclosed in theboot2docker
VM.
Then the CMD ["docker", "--tlsverify", "ps"]
statements ensures the connection is made through HTTP instead of the UNIX socket, implicitly using the certificates located in the /root/.docker
folder.