How do I create or edit files in the remote docker environment?

It's possible to edit or create files on the remote docker environment with an ssh command.

Note that the -a in the tee command will append to a file if it exists, or create the file if it does not exist. In this example we are creating a daemon.json file in /etc/docker with configuration to use a registry-mirror. Then we execute sudo service docker restart on the remote environment to restart the docker daemon, which will pick up the new configuration. Then docker system info executes in the primary container, and will report the successful configuration of docker.

The strategy can be used for other services as well that need to be configured in the remote environment.

version: 2.1

jobs:
build:
docker:
- image: circleci/python:3
steps:
- setup_remote_docker:
version: "19.03.8"
- run:
command: |
cat \<< EOF | ssh remote-docker "sudo tee -a /etc/docker/daemon.json"
{
"registry-mirrors": ["https://mirror.gcr.io"]
}
EOF
ssh remote-docker "sudo service docker restart"
docker system info
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.