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 while attempting connect to the remote Docker daemon which was set up by the setup_remote_docker step, you can try running docker and setting the , following options to ensure that the right Docker daemon is being connected to.

  • --tlsverify
  • -H
  • --tlscacert
  • --tlscert
  • --tlskey

First, 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:


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?
9 out of 21 found this helpful



Article is closed for comments.