In my HomeLab I have two RancherOS hosts, and now I added 7 Raspberry Pi's and I'm planning on adding more hosts in the future. Initially I was just connecting via ssh and executing commands on the hosts. For Rancher running docker-compose is a little extra work, as it doesn't have it available. The quickest solution I have vor it is:

docker run --rm -it -v ${PWD}:/rx -v /var/run/docker.sock:/var/run/docker.sock -w /rx docker/compose up -d

This command:

  • docker run gets docker-compose container from docker hub
  • --rm removes the container after closing it, or after the command finishes
  • -it launches interactive terminal
  • -v ${PWD}:/rx mounts current directory as /rx on the container
  • -v /var/run/docker.sock:/var/run/docker.sock mounts local docker socket, so that the compose container can control your docker instance
  • -w sets the working directory
  • docker/compose is the name of the image from docker hub
  • up -d is the command we send to the container

All this is equivalent to running docker-compose up -d but without having compose installed

This approach is not optimal for having multiple remote hosts, so I was researching how could I use my local docker engine and control the remote hosts.

The quickest way is to run export DOCKER_HOST=ssh://username@<machine.ip> , that makes docker use the remote HOST. There is a newer way using docker context. It allows you to set and use multiple configs and easily switch between them.

To list the existing contexts run docker context ls

To create a new context run docker context create <context_name> --docker "host=ssh://<username>@<host or ip>"

To use the newly created context you can either run docker --context <context_name> command for each command or run docker context use <context_name>. Important note is that if you set DOCKER_HOST variable it will override docker context, so make sure to unset it.

docker-compose

What about docker-compose? The new-new version supports docker contexts, but it's still in RC as I write this post, so the only other way is to set DOCKER_HOST, it will use it automatically.

paramiko.ssh_exception.ChannelException: ChannelException(1, 'Administratively prohibited') or similar errors are caused by sshd MaxSessions default value of 10, where docker-compose tries to open 25 connections. Solution is to edit /etc/ssh/sshd_config and changing MaxSessions to something above 25.

Links: