How to run docker commands when SSH-ing into a rebuild that uses a remote Docker engine

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:

DOCKER_CERT_PATH=/tmp/docker-certs970508324
DOCKER_HOST=tcp://35.237.187.184:2376

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 
Was this article helpful?
1 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.