docker-machine is a really powerful tool to control your remote docker daemons. Let’s see how to configure everything to manage your remote containers easily from your local host.
Remote server
Docker machine user
Add a user on the remote server to control your docker daemon:
Create a custom ssh key and add it on the remote server to allow connection with this user.
Sudo or not sudo
Your user must have sudo
access without asking for password:
Netstat
Your user must have netstat
access.
As I’m using a grs kernel I need to create a wrapper to add netstat
access
for the dockeradmin user:
Iptables
By default docker-machine uses port 2376
to communicate with docker daemons.
Of course we need to open this port on the remote server:
Docker daemon
docker-machine
and generic
driver do not work with aufs
storage driver.
So we need to explicitly define the storage-driver
as devicemapper
on the server daemon side and on the docker-machine client.
On my remote server, my processes are managed by systemd
,
a part of this configuration is automatically updated by the docker-machine client:
Local configuration
Install docker-machine
https://docs.docker.com/machine/install-machine/
Create your first machine
The command to start your docker-machine
is the following. Note the use of specific:
- ssh port
- ssk key
Very important, the --engine-storage-driver devicemapper
configuration:
Switch between environments
Execute a docker ps
and you will control your remote daemon and see your remote containers.
Reset your client configuration to manage your local containers.
Sources
- http://www.thegeekstuff.com/2016/02/docker-machine-create-generic/
- https://docs.docker.com/engine/admin/systemd/
- https://blog.dahanne.net/2015/10/07/adding-an-existing-docker-host-to-docker-machine-a-few-tips/
- https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/
- https://docs.docker.com/engine/admin/configuring/