You may sometimes want to run docker commands when SSH-ed into a rebuild for diagnostic purposes.
However, you may encounter the following error message when running a docker command in the SSH session:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
If you are encountering the above error in connecting to the remote Docker daemon which was set up by the setup_remote_docker step, you can try running docker and setting the --tlsverify, -H, --tlscacert, --tlscert and --tlskey options to ensure that the right Docker daemon is being connected to.
First, please check the output of the "Setup a remote Docker engine" step in your build, to get the host and cert path of the remote Docker engine set up by CircleCI.
For convenience, you can set the environment variables in your SSH session, for example:
And then, you can reference the above environment variables when running docker commands with the --tlsverify, -H, --tlscacert, --tlscert and --tlskey options specified.
The example below shows how the docker ps command may be successfully run with the options specified.
docker --tlsverify -H=$DOCKER_HOST --tlscacert=$DOCKER_CERT_PATH/ca.pem --tlscert=$DOCKER_CERT_PATH/cert.pem --tlskey=$DOCKER_CERT_PATH/key.pem ps