Docker-Machine

Lister les machines

sudo docker-machine ls

NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
machine1 - virtualbox Stopped Unknown

Créer une machine

sudo docker-machine create [OPTION] <MACHINE NAME>

sudo docker-machine create --driver virtualbox machine1

Lors de la création d'une machine l'option --driver doit toujours être spécifier :

sudo docker-machine create --driver virtualbox machine1

Des options additionnelles peuvent être données :

sudo docker-machine create --driver virtualbox \
--virtualbox-memory=2048 \
--virtualbox-disk-size=5000 \
machine2
Running pre-create checks...
(machine1) Image cache directory does not exist, creating it at /root/.docker/machine/cache...
(machine1) No default Boot2Docker ISO found locally, downloading the latest release...
(machine1) Latest release for github.com/boot2docker/boot2docker is v19.03.5
(machine1) Downloading /root/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.5/boot2docker.iso...
(machine1) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(machine1) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/machine1/boot2docker.iso...
(machine1) Creating VirtualBox VM...
(machine1) Creating SSH key...
(machine1) Starting the VM...
(machine1) Check network to re-create if needed...
(machine1) Waiting for an IP...
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 boot2docker...
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 machine1

Supprimer une machine

sudo docker-machine rm <MACHINE NAME>

About to remove machine1
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed machine1

Variables d'environnements

sudo docker-machine env <MACHINE NAME>

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/machine1"
export DOCKER_MACHINE_NAME="machine1"
# Run this command to configure your shell:
# eval $(docker-machine env machine1)

Visualiser les variables de la machine cible

env | grep DOCKER

DOCKER_TLS_VERIFY=1
DOCKER_CERT_PATH=/root/.docker/machine/machines/machine1
DOCKER_MACHINE_NAME=machine1
DOCKER_HOST=tcp://192.168.99.100:2376

Définir des variables d'environnement

eval $(sudo docker-machine env <MACHINE NAME>)

Reinitialiser la machine pour revenir au daemon local

eval $(sudo docker-machine env -u)