MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker Machine Tutorials: Commands and Example

Docker Machine is a command-line tool that creates virtual machines, installs Docker Engine on them, and points your local docker client at them. This page explains the docker-machine commands listed above, fixes a few problems in that list, and walks through a full lifecycle with the VirtualBox driver. Docker Machine has been deprecated and archived by Docker, so the page also covers what to use instead.


> docker-machine ls
> docker-machine create --driver virtualbox server1
> docker-machine create --driver virtualbox server1
> docker-machine ip default
> docker-machine status default
> docker-machine env default
> docker-machine
> docker-machine stop default
> docker-machine start default
> docker-machine env server1
> eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env server1)Code language: JavaScript (javascript)

Read this first: Docker Machine is deprecated

Docker Machine and Docker Toolbox are no longer maintained. Docker archived the docker/machine repository, and the last official release was v0.16.2. The commands on this page still work where the tool is installed, so the information is useful for maintaining older environments, following legacy course material, or understanding how remote Docker hosts work. Do not use Docker Machine for new projects.

NeedCurrent replacement
Run Docker on a Windows or macOS laptopDocker Desktop, Rancher Desktop or Colima (macOS/Linux)
Point the local CLI at a remote Docker hostdocker context with an SSH endpoint
Create disposable Linux VMs for labsVagrant, Multipass, or cloud VMs provisioned with Terraform
Multi-node clustersDocker Swarm (docker swarm init) or Kubernetes

Prerequisites

  • The Docker CLI (docker) installed on your workstation.
  • VirtualBox installed. On Windows, Hyper-V and features that depend on it (WSL 2, Docker Desktop) can conflict with VirtualBox, depending on your VirtualBox version.
  • The docker-machine binary. Docker Toolbox for Windows bundled it at C:\Program Files\Docker Toolbox\docker-machine.exe. On Linux or macOS you can install the last release binary as shown below.
  • An Intel/AMD (x86_64) host. The VirtualBox driver and the boot2docker ISO do not work on Apple Silicon Macs.
# Linux / macOS (x86_64): install the final Docker Machine release
base=https://github.com/docker/machine/releases/download/v0.16.2
curl -L $base/docker-machine-$(uname -s)-$(uname -m) -o /tmp/docker-machine
sudo install /tmp/docker-machine /usr/local/bin/docker-machine
docker-machine versionCode language: PHP (php)

What each command in the example above does

CommandPurpose
docker-machine lsLists all machines with their driver, state, Docker URL and Docker version.
docker-machine create --driver virtualbox server1Creates a VirtualBox VM named server1 from the boot2docker ISO, installs Docker, and generates TLS certificates.
docker-machine ip defaultPrints the IP address of the machine named default.
docker-machine status defaultPrints Running, Stopped, Saved or Error.
docker-machine env defaultPrints the environment variables that point the Docker CLI at that machine. It does not change anything by itself.
docker-machineWith no subcommand, prints the help and the list of subcommands.
docker-machine stop default / start defaultShuts down or boots the VM. The IP address can change after a restart.
eval $(... env server1)Runs the printed export lines in the current shell, so later docker commands talk to server1.

Note: The machine default only exists if you created it yourself or ran the Docker Quickstart Terminal from Docker Toolbox, which creates it automatically. If you only ran the create command above, use server1 instead.

Corrected command list

The example above has a duplicated create line (the second run fails with Docker machine "server1" already exists), mixes the machine names default and server1, and includes > prompt characters that break copy and paste. Here is a consistent version that uses one machine:

docker-machine ls
docker-machine create --driver virtualbox server1
docker-machine ip server1
docker-machine status server1
docker-machine env server1
eval $(docker-machine env server1)   # bash/zsh, including Git Bash
docker-machine stop server1
docker-machine start server1
docker-machine regenerate-certs -f server1   # needed if the IP changed after startCode language: PHP (php)

The final line in the original, eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env server1), only works in a bash shell on Windows such as Git Bash or the Docker Quickstart Terminal. It fails in Command Prompt and PowerShell, which need different syntax:

# PowerShell
& "C:\Program Files\Docker Toolbox\docker-machine.exe" env --shell powershell server1 | Invoke-Expression

# Command Prompt (cmd.exe)
@FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd server1') DO @%iCode language: PHP (php)

End-to-end walkthrough with expected output

  1. Create the machine: docker-machine create --driver virtualbox --virtualbox-memory 2048 --virtualbox-cpu-count 2 server1. The first run downloads the boot2docker ISO, so it takes a few minutes.
  2. Check it: docker-machine ls should show server1 with state Running and a URL like tcp://192.168.99.100:2376.
  3. Look at the environment: docker-machine env server1.
  4. Apply it: eval $(docker-machine env server1). docker-machine ls now shows * in the ACTIVE column for server1.
  5. Run a container on the VM: docker run -d -p 8080:80 nginx, then open http://$(docker-machine ip server1):8080. The port is published on the VM's IP, not on localhost.
  6. Switch back to your local Docker engine: eval $(docker-machine env -u).
$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER      ERRORS
server1   -        virtualbox   Running   tcp://192.168.99.100:2376           v19.03.12

$ docker-machine env server1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/user/.docker/machine/machines/server1"
export DOCKER_MACHINE_NAME="server1"
# Run this command to configure your shell:
# eval $(docker-machine env server1)Code language: PHP (php)

Your IP address, paths and Docker version may be different. Once the variables are set, every docker command in that shell (for example those in docker run with examples) runs against the VM.

Other useful commands

CommandWhat it does
docker-machine ssh server1Opens a shell on the VM. Add a command to run it once, e.g. docker-machine ssh server1 "df -h".
docker-machine scp file.txt server1:/home/docker/Copies files between the host and the machine.
docker-machine activeShows which machine the current shell points at.
docker-machine inspect server1Prints the machine's full JSON configuration.
docker-machine url server1Prints the Docker daemon URL.
docker-machine restart server1Restarts the VM.
docker-machine rm -y server1Deletes the VM and its certificates. Containers and volumes on it are lost.
docker-machine create --driver generic --generic-ip-address 10.0.0.5 --generic-ssh-user ubuntu --generic-ssh-key ~/.ssh/id_rsa server2Installs Docker on an existing Linux host over SSH instead of creating a VM.

Common errors and fixes

Error or symptomCauseFix
VBoxManage: error: ... E_ACCESSDENIED when creating the host-only adapterNewer VirtualBox releases on Linux and macOS only allow host-only networks in 192.168.56.0/21 by default. Docker Machine uses 192.168.99.1/24.Add --virtualbox-hostonly-cidr "192.168.56.1/24" to create, or allow the range in /etc/vbox/networks.conf (e.g. * 192.168.99.0/24).
This computer doesn't have VT-X/AMD-v enabledHardware virtualisation is off in the BIOS/UEFI, or Hyper-V is holding it on Windows.Enable VT-x/AMD-V in firmware. On Windows, disable Hyper-V or use Docker Desktop instead.
x509: certificate is valid for 192.168.99.100, not 192.168.99.101The VM got a new IP after a restart.docker-machine regenerate-certs -f server1, then re-run eval $(docker-machine env server1).
Cannot connect to the Docker daemon after opening a new terminalEnvironment variables apply only to the shell where you ran eval.Run the eval command again in each new shell.
Docker machine "server1" already existscreate was run twice with the same name.Use docker-machine start server1, or remove it with docker-machine rm server1 first.

Security notes and the modern way to reach a remote engine

  • Docker Machine secures the daemon on port 2376 with TLS client certificates stored under ~/.docker/machine/machines/<name>. Anyone who has those files has root-equivalent access to the host, so protect them like SSH private keys.
  • Do not open port 2375 (the unencrypted Docker API) on any host.
  • boot2docker images are no longer updated, so they do not receive security fixes. Do not use them for anything exposed to a network.

To control a remote Docker host today, use Docker contexts over SSH. No extra tool or certificate management is needed:

docker context create server1 --docker "host=ssh://ubuntu@10.0.0.5"
docker context use server1
docker ps            # runs against the remote engine
docker context use defaultCode language: PHP (php)

Frequently asked questions

Is Docker Machine still supported?

No. Docker deprecated Docker Machine and Docker Toolbox and archived the project. The last release is v0.16.2. Use Docker Desktop, Colima or Rancher Desktop for local engines and docker context for remote ones.

What replaced docker-machine env?

docker context create and docker context use. They switch the CLI between engines without setting environment variables, and the setting persists across new terminals.

Why can't I reach my container on localhost when using Docker Machine?

Containers run inside the VM, so published ports are bound to the VM's IP address. Use docker-machine ip <name> to get the address, then browse to that IP and port.

How do I stop my shell from using the Docker Machine VM?

Run eval $(docker-machine env -u) in bash or zsh. It unsets DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH and DOCKER_MACHINE_NAME, so the CLI goes back to the local engine.

Does Docker Machine work on Apple Silicon Macs?

Not with the VirtualBox driver. The boot2docker ISO is x86_64-only. Use Docker Desktop or Colima on Apple Silicon.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Puppet Learning VM Setup Guide: Import, Networking, SSH Access, and Troubleshooting

Learn how to set up the Puppet Learning VM from the OVA download through first login, networking, and web access. This revised guide also consolidates the most useful troubleshooting fixes from the original courseware.

Read More

How to check VT-X/AMD-v enabled or not in your Laptop?

Method 1 – Using task Manager If you have Windows 10 or Windows 8 operating system, the easiest way to check is by opening up Task Manager->Performance Tab….

Read More

Chef Tutorials: Test Kitchen – Example of kitchen.yml with VAGRANT and VirtualBox

How to test Chef recipes/cookbooks on your workstation with VAGRANT and VirtualBox using Test Kitchen Install Test Kitchen, VAGRANT and VirtualBox: Chef Test Kitchen: Test Kitchen is…

Read More

Vagrant Tutorial: Basic Workflow

Step 1- Download and Install VirtualBox https://www.virtualbox.org/wiki/Downloads Step 2- Download and Install Vagrant https://www.vagrantup.com/downloads Step 3 – Add a Box uRL to Vagrant Step 4 – Creating…

Read More

How To Create Linux Virtual Machine Using VirtualBox

Step by Step with Screenshot – https://www.devopsschool.com/blog/how-to-install-linux-on-windows-or-virtual-machine/ Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world…

Read More

DevOps – Linux & VirtualBox & Vagrant Demo Tutorial

Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x