Using Docker On Windows: What Are Machines?
Using Docker On Windows: What Are Machines?
Overview
When using Docker on Windows or OS X you may face some additional challenges that those on Linux won't. Since Docker only runs natively on
Linux you will have an additional layer between your OS (Windows or OS X) and the Docker engine. In most cases this will be a Virtual Box VM
but could also be an Amazon EC2 instance or other virtual machine. The topic is oriented to Windows (8+) environment and assumes you have
already completed the Docker Toolbox installation instructions. The commands and concepts explained here should also apply to OS X in the
same ways.
Docker Machine can manage multiple target machines. Docker Client can be pointed to one machine at a time.
The default Docker machine
When you launch the Docker Quickstart Terminal the start script will automatically check for a machine called default and create it if it does not
exist. Once created this machine is started automatically for you. This machine is good enough for many standard use cases, but may not have
enough memory or hard drive space for enterprise applications such as Oracle SOA Suite and BPM. The default machine information can be
obtained with a docker info command in the terminal window. The machine has 20 GB of hard disk and 2gb of memory by default.
Because of the limited memory and disk space it is recommended that you delete and re-create the default docker machine with more
capacity. By re-creating the machine with the same name the Docker Quickstart Terminal will still start the machine automatically for
you and configure the environment automatically for the docker client.
It is also possible to update the existing machine as well, but this shouldn't be necessary.
Both methods are described below, although re-creating is the recommended option.
The Database image user password will expire soon after creating it. To connect to the database use sys as sysdba/oracle.
1. List the current Docker machines using the docker-machine ls command. The output below shows the standard or "default" machine
created by boot2docker.
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL
SWARM ERRORS
default - virtualbox Running tcp://192.168.99.101:2376
2. Run the docker-machine rm default command to remove the default docker machine.
$ docker-machine rm default
(default) Stopping VM...
Successfully removed default
3. Run the following command to create a new Docker machine named "default" using the Oracle VirtualBox driver with 50 GB of hard disk
space, 8 GB of memory and 4 CPUs. This command will create and start the machine.
$ docker-machine create --virtualbox-disk-size 50000
--virtualbox-memory 8192 --virtualbox-cpu-count 4 -d virtualbox
default
Running pre-create checks...
Creating machine...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting VM...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
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 Docker to this machine, run: C:\Program
Files\Docker Toolbox\docker-machine.exe env default
4. List the Docker machines once again and you should see the new default machine in a Running state.
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL
SWARM ERRORS
default - virtualbox Running tcp://192.168.99.103:2376
5. Each Docker machine will have it's own IP address assigned. With the new machine setup we need to setup the environment to use the
new IP. Run the docker-machine env default command. It will produce output like that shown below.
6. The recommended eval command will configure all of the required environment variables for the docker client, although the spaces in the
path to docker-machine will cause problems. docker-machine should already be on your path so you can simply execute the following
command to setup your environment. You will not need to do this every time because the Docker Quickstart Terminal executes this for
6.
7. You can now execute the docker info command as well as an export command to confirm your environment has been setup correctly.
You will see DOCKER_HOST and DOCKER_MACHINE_NAME set, the Total Memory on the machine is 8gb and there are now 4 CPUs.
$ docker info
Containers: 0
Images: 0
Server Version: 1.9.1
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 0
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.1.13-boot2docker
Operating System: Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b -
Fri Nov 20 1
9:33:59 UTC 2015
CPUs: 4
Total Memory: 7.79 GiB
Name: default
ID: MKNO:PELR:IPVT:BH4C:4HUM:KKA3:VQPM:MUZB:FAIW:LQYU:VXDB:LIVB
Debug mode (server): true
File Descriptors: 11
Goroutines: 18
System Time: 2016-02-23T18:41:14.542267991Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
provider=virtualbox
Updating the Default Docker Machine
If you follow the steps below it is because you do not wish to create a new Docker machine but simply want to update the default Docker machine
created by the installation. This should only be done if you have already been working in the default machine and don't want to lose containers or
images you have there.
1. First, you need to locate where VBoxManage.exe is located on your Windows machine.
2. Open the Docker Quickstart Terminal and wait for the $ prompt.
3. Stop the default machine (docker-machine stop default) so that it can be modified
4. Run VBoxManage.exe by pasting the specific path into the Docker Terminal and adding an additional backslash to the path name to
escape the backlash character. Append "modifyvm default --memory 8192 --cpus 4" to the VBoxManage command as shown below to
increase the memory to 8gb and the CPUs to 4.
5. After running the memory alteration start the default machine (docker-machine start default) and run docker info command to verify
the change.
$ docker-machine start default
(default) Starting VM...
Started machines may have new IP addresses. You may need to re-run
the `docker-machine env` command.
$ docker info
Containers: 1
Images: 99
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 101
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.1.13-boot2docker
Operating System: Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b -
Fri Nov 20 19:33:59 UTC 2015
CPUs: 4
Total Memory: 5.821 GiB
Name: default
ID: GWF6:E45E:F4TZ:74QW:MLFH:U557:D7SQ:P7O3:ZJKR:667G:UYX5:L6EF
Debug mode (server): true
File Descriptors: 17
Goroutines: 29
System Time: 2015-12-18T21:16:40.983712143Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
provider=virtualbox
Troubleshooting
Starting Docker
Running any docker command you may see the following error (e.g. docker ps).
$ docker ps
Get http://127.0.0.1:2375/v1.19/containers/json: dial tcp
127.0.0.1:2375: ConnectEx tcp: No connection could be made because the
target machine actively refused it.. Are you trying to connect to a
TLS-enabled daemon without TLS?
This means that the docker client is not able to communicate with your docker machine. When starting the Docker Quickstart Terminal your
environment is automatically configured for the default machine and the IP for that machine is printed when the terminal is first opened.
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
If you are using the default docker machine still you should verify the machine is running properly in Virtual Box.
If you are not using a machine called default then you will need to start your machine and setup your own environment using the docker-machine
commands below each time you open the Docker Quickstart Terminal.
You can also modify the script C:\Program Files\Docker Toolbox\start.sh and update the line VM=default to have the Quickstart Terminal start
and configure your environment for a different machine than default. In this example it will now start the avio-machine VM each time the terminal
is opened.
#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong...
Press any key to continue..."' EXIT
VM=avio-machine
DOCKER_MACHINE=./docker-machine.exe
docker-machine ls
Create a Machine
docker-machine active
docker-machine ip machine-name
Connect to a Machine
Summary
Despite some of the additional work needed to accommodate the Docker on Windows, using it is still advantageous as the images are built,
tested and up to date with patches.