Rocker
Deprecation Notice
This repository is deprecated. As of Docker 18.09, connecting to Docker daemon over SSH is built-in, so this helper script is no longer necessary.
Remote Docker is a small wrapper around the docker
client that
extends it with support for securely connecting to a remote dockerd
daemon
via SSH.
In short, it implements the ssh://
protocol for the --host
parameter in the
Docker CLI.
Why? Because I use a MacBook 12" which is essentially a tablet in laptop form,
so offloading the dockerd
daemon to a more powerful machine makes development
a lot faster. This also allows for an easy way to share running docker
containers between teammates for collaboration, or if you develop on more than
one machine.
Aims to support all docker features, in particular:
- Port publishing (
-p
) by SSH local port forwarding. - Volume mounts (
-v
) by a reversesshfs
from the server to local.
Usage
One-time with -H
/--host
:
$ docker -H ssh://user@myserver.com run --rm -p 80:80 nginx
Make it permanent by setting DOCKER_HOST
:
$ export DOCKER_HOST=ssh://user@myserver.com
$ docker run --rm -p 80:80 nginx
Setup
Local
- Install the
docker
client (Docker for Mac for MacOS). - Setup an SSH server running locally, for the reverse
sshfs
mount to work. - Add the remote docker server's public key to your local
~/.ssh/authorized_keys
. - Run
./install.sh
from this repo to install/usr/local/bin/docker
and friends. - Set the
DOCKER_HOST
env var or usedocker -H
with anssh://
protocol to invoke "rocker". - To avoid getting a
Password:
prompt every time you invokedocker
, you must add to the end of your/etc/sudoers
file:Be sure to replace# Make `sudo -E rockerd` work without a password YOUR_USERNAME ALL=(root) NOPASSWD:SETENV: /usr/local/bin/rockerd
YOUR_USERNAME
with your actual username, and update the file location if you installed it to a non-default location.
Server
Instructions are for an Ubuntu server:
- Setup
docker
. - Setup SSH server.
- Install
sshfs
:$ sudo apt-get install sshfs
- Create
/mnt/sshfs
with full permissions for the user you will log in as.$ sudo mkdir -p /mnt/sshfs $ sudo chmod 777 /mnt/sshfs
Sub-commands
All rockerd
commands expect either the DOCKER_HOST
environment variable to be
set, or for the --host
/-H
CLI argument to be specified.
SSH into the remote docker machine
$ rockerd ssh
Invokes ssh
with the configured docker host. The ssh connection uses the
control socket that the rockerd
daemon creates, so it does not need to perform
a new handshake, etc.
Explicitly forwarding a port to localhost
Publish port 80 from the remote docker machine to localhost:
$ rockerd port publish 80
When using docker run --net=host
, the ports that the container binds to are
not known. In this case, it can be useful to manually publish the desired port
by running the rockerd port publish
command.
When you no longer want to have the port being forwarded, use unpublish
:
$ rockerd port unpublish 80