Docker

Docker Machine

Create a new virtual machine (multi-platform)

docker-machine create --driver virtualbox myvm1
Replace myvm1 with your desired VM name.

Create a new virtual machine using Hyper-V on Windows 10 (specify virtual switch)

docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1

Replace myswitch with the actual name of your Hyper-V virtual switch and myvm1 with your desired VM name.

View information about a VM

docker-machine env myvm1
Replace myvm1 with the name of your existing VM.

List nodes in a swarm (requires SSH access to the VM)

docker-machine ssh myvm1 "docker node ls"

Replace myvm1 with the name of your VM running the swarm master.

Inspect a specific node in a swarm (requires SSH access to the VM)

docker-machine ssh myvm1 "docker node inspect <node ID>"
Replace <node ID> with the actual ID of the node you want to inspect. You can get this ID from the previous command's output.

View worker join token for a swarm (requires SSH access to the VM)

docker-machine ssh myvm1 "docker swarm join-token -q worker"

Replace myvm1 with the name of your VM running a swarm worker.

Open an SSH session to a VM

docker-machine ssh myvm1

Replace myvm1 with the name of your VM. Type "exit" to end the SSH session.

Make a worker leave the swarm (requires SSH access to the VM)

docker-machine ssh myvm2 "docker swarm leave"

Replace myvm2 with the name of the worker VM you want to remove from the swarm.

Force a swarm master to leave and shut down the swarm (requires SSH access to the VM)

docker-machine ssh myvm1 "docker swarm leave -f"

Use this command with caution as it will disrupt the entire swarm.

Start a stopped VM

docker-machine start myvm1
Replace myvm1 with the name of your stopped VM.

Stop all running VMs

docker-machine stop $(docker-machine ls -q)

This command will stop all running VMs. Use with caution!

Delete all VMs and their disk images

docker-machine rm $(docker-machine ls -q)

This command will permanently delete all VMs and their associated disk images. Use with extreme caution!

Copy a file to a VM (requires SSH access to the VM)

docker-machine scp docker-compose.yml myvm1:~

Deploy an application using docker-compose on a VM (requires SSH access to the VM)

docker-machine ssh myvm1 "docker stack deploy -c <file> <app>"

On this page