docker machine, what are you?
So how does it work? When you create a machine, it sets some env vars:
export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://127.0.0.1:2376" export DOCKER_CERT_PATH="/root/.docker/machine/machines/mylocalmachine" export DOCKER_MACHINE_NAME="mylocalmachine"
These env vars are used by the docker daemon to determine where to run its commands. One other thing to note is that if you set some remote computer to be a 'docker machine' and it does not yet have a docker daemon installed, docker machine will install the docker daemon as part of setting it up as a docker machine.
$ curl -L https://github.com/docker/machine/releases/download/v0.12.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine $ docker-machine version docker-machine version 0.12.2, build 9371605
Create some ssh keys and access stuffs
$ ssh-keygen -t rsa $ ssh 127.0.0.1
Ensure the key is present in ~/.ssh/authorized_keys and the host is in the ~/.ssh/known_hosts file
$ docker-machine create --driver generic --generic-ip-address=127.0.0.1 --generic-ssh-key /root/.ssh/id_rsa --generic-ssh-user root mylocalmachine Running pre-create checks... Creating machine... (mylocalmachine) Importing SSH key... Waiting for machine to be running, this may take a few minutes... Detecting operating system of created instance... Waiting for SSH to be available... Detecting the provisioner... Provisioning with ubuntu(upstart)... Installing Docker... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Checking connection to Docker... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env mylocalmachine
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS mylocalmachine - generic Running tcp://127.0.0.1:2376 v17.06.0-ce
Show machine environment variables
$ docker-machine env mylocalmachine export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://127.0.0.1:2376" export DOCKER_CERT_PATH="/root/.docker/machine/machines/mylocalmachine" export DOCKER_MACHINE_NAME="mylocalmachine" # Run this command to configure your shell: # eval $(docker-machine env mylocalmachine)
Switch to the machine named "mylocalmachine"
$ eval $(docker-machine env mylocalmachine) $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS mylocalmachine * generic Running tcp://127.0.0.1:2376 v17.06.0-ce
$ docker-machine create --driver generic --generic-ip-address=127.0.0.1 --generic-ssh-key /root/.ssh/id_rsa --generic-ssh-user root mylocalmachine2 $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS mylocalmachine * generic Running tcp://127.0.0.1:2376 v17.06.0-ce mylocalmachine2 * generic Running tcp://127.0.0.1:2376 v17.06.0-ce
Switch to the second machine
$ eval $(docker-machine env mylocalmachine2)
$ docker-machine rm mylocalmachine About to remove mylocalmachine WARNING: This action will delete both local reference and remote instance. Are you sure? (y/n): y Successfully removed mylocalmachine $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS