How do I run commands in the remote Docker environment?

Although only Docker commands are automatically executed in the remote Docker environment, you can programmatically execute any set of commands in the remote Docker environment by shelling into it and chaining any subsequent commands to your shell command. To SSH into the remote Docker environment, run ssh remote-dockerwhile SSH'd into any CircleCI job that uses setup_remote_docker or execute it programmatically in a run step. (Make sure the setup_remote_docker step runs first, otherwise, your SSH command will fail!)

Chaining a command to this SSH command in a headless fashion, i.e., as part of your CircleCI job, could look something like:

run: |
  ssh remote-docker \
     echo "this echo command will be executed in the remote Docker environment \
     rather than the initial job container itself"

The challenge presented here is that only a singular command can be passed to the SSH shell—for example, if you run ssh remote-docker touch file1 && touch file2file1 will be created in the remote Docker environment, but file2will be created in your job's local container. So, if you want to do run a more complex set of commands in the remote Docker environment, programmatically, then you need to find a way to have them be executed as a single command.

Some good approaches (namely, use a "here document" or save your commands to a shell script which you then pipe into your ssh command) are outlined here:


Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.