Rocker
Remote Docker: docker -H ssh://user@myserver.com run -p 80:80 nginx
Install / Use
/learn @TooTallNate/RockerREADME
Rocker <img width="38" src="https://camo.githubusercontent.com/cd082848a3f8f00d426e36a8fe232a8d44b0e9c6/68747470733a2f2f656d6f6a692e736c61636b2d656467652e636f6d2f5430434151303054552f726f636b6f75742f326631653833663338623161643435392e676966" />
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 reversesshfsfrom 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
dockerclient (Docker for Mac for MacOS). - Setup an SSH server running locally, for the reverse
sshfsmount to work. - Add the remote docker server's public key to your local
~/.ssh/authorized_keys. - Run
./install.shfrom this repo to install/usr/local/bin/dockerand friends. - Set the
DOCKER_HOSTenv var or usedocker -Hwith anssh://protocol to invoke "rocker". - To avoid getting a
Password:prompt every time you invokedocker, you must add to the end of your/etc/sudoersfile:
Be sure to replace# Make `sudo -E rockerd` work without a password YOUR_USERNAME ALL=(root) NOPASSWD:SETENV: /usr/local/bin/rockerdYOUR_USERNAMEwith 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/sshfswith 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
