Chapter 3. Installing Docker

The steps required to install Docker vary depending on the primary platform you use for development and the Linux distribution that you use to host your applications in production. Since Docker is a technology built around Linux containers, people developing on non-Linux platforms will need to use some form of virtual machine or remote server for many parts of the process.

In this chapter, we discuss the steps required to get a fully working Docker development environment set up on most modern desktop operating systems. First we’ll install the Docker client on your native development platform, then we’ll get a Docker server running on Linux. Finally we’ll test out the installation to make sure it works as expected.

Although the Docker client can run on Windows and Mac OS X to control a Docker Server, Docker containers can only be built and launched on Linux. Therefore, non-Linux systems will require a virtual machine or remote server to host the Linux-based Docker server.

Important Terminology

Below are a few terms that we will continue to use throughout the book and whose meanings you should become familiar with.

Docker client

The docker command used to control most of the Docker workflow and talk to remote Docker servers.

Docker server

The docker command run in daemon mode. This turns a Linux system into a Docker server that can have containers deployed, launched, and torn down via a remote client.

Docker images

Docker images consist of one or more filesystem layers and some important metadata that represent all the files required to run a Dockerized application. A single Docker image can be copied to numerous hosts. A container will typically have both a name and a tag. The tag is generally used to identify a particular release of an image.

Docker container

A Docker container is a Linux container that has been instantiated from a Docker image. A specific container can only exist once; however, you can easily create multiple containers from the same image.

Atomic host

An atomic host is a small, finely tuned operating system image, like CoreOS and Project Atomic, that supports container hosting and atomic OS upgrades.

Note

The Docker ecosystem is changing very rapidly as the technology evolves to become more robust and solve a broader range of problems. Some features discussed in this book and elsewhere may become deprecated. To see what has been tagged for deprecation and eventual removal, visit this URL: https://docs.docker.com/engine/misc/deprecated/.

Docker Client

The Docker client natively supports 64-bit versions of Linux and Mac OS X due to the Unix underpinnings of both operating systems. There have been reports of people getting Docker to run on 32-bit systems, but it is not currently supported.

The majority of popular Linux distributions can trace their origins to either Debian or Red Hat. Debian systems utilize the deb package format and Advanced Package Tool (apt) to install most prepackaged software. On the other hand, Red Hat systems rely on rpm (Red Hat Package Manager) files and Yellowdog Updater, Modified (yum) to install similar software packages.

On Mac OS X and Microsoft Windows, native GUI installers provide the easiest method to install and maintain prepackaged software. On Mac OS X, Homebrew is also a very popular option among technical users.

Note

To develop with Docker on non-Linux platforms, you will need to leverage virtual machines or remote Linux hosts to provide a Docker server. Docker Machine, Boot2Docker, and Vagrant, which are discussed later in this chapter, provide some approaches to solving this issue.

Linux

It is strongly recommended that you run Docker on a modern release of your preferred Linux distribution. It is possible to run Docker on some older releases, but stability may be a significant issue. Generally a 3.8 or later kernel is required, and we advise you to use the newest stable version of your chosen distribution. The directions below assume you are using a recent, stable release.

Ubuntu Linux 14.04 (64-bit)

To install Docker on a current installation, run the following commands:

$ sudo apt-key adv 
  --keyserver hkp://p80.pool.sks-keyservers.net:80 
  --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Next you will need to add the correct apt respository into your sources list.

$ sudo vim /etc/apt/sources.list.d/docker.list

Delete everything in /etc/apt/sources.list.d/docker.list and replace it with a single line from the list below, based on the version of Ubuntu that you are using:

# Debian Wheezy
deb https://apt.dockerproject.org/repo debian-wheezy main

# Debian Jessie
deb https://apt.dockerproject.org/repo debian-jessie main

# Debian Stretch/Sid
deb https://apt.dockerproject.org/repo debian-stretch main

# Ubuntu Precise
deb https://apt.dockerproject.org/repo ubuntu-precise main

# Ubuntu Trusty
deb https://apt.dockerproject.org/repo ubuntu-trusty main

# Ubuntu Utopic
deb https://apt.dockerproject.org/repo ubuntu-utopic main

# Ubuntu Vivid
deb https://apt.dockerproject.org/repo ubuntu-vivid main

# Ubuntu Wily
deb https://apt.dockerproject.org/repo ubuntu-wily main

Then run the following commands to install Docker.

$ sudo apt-get update
$ sudo apt-get purge lxc-docker* docker.io*  # Remove obsolete versions
$ sudo apt-get install docker-engine

Fedora Linux 21 (64-bit)

To install the correct Docker packages on your system, run the following command:

$ curl -sSL https://get.docker.com/ | sh

The easiest way to install the Docker Yum repositories on Red Hat–based systems is to use the script provided by Docker. Security-conscious people will however, prefer to create the repo file by hand.

Caution

It is never a great idea to run a script from the Internet and pipe it into a shell. Even if it comes from a trusted source, sites get compromised frequently. If you are going to use this method, at least download the script and read it before piping it into a shell.

To create the required file by hand for Fedora 21, you would do the following:

cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/fedora/21
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

If you are running another recent Red Hat–based distribution, you can replace the URL above with the correct entry from this list:

CentOS 6 & RHEL 6: https://yum.dockerproject.org/repo/main/centos/6

CentOS 7 & RHEL 7: https://yum.dockerproject.org/repo/main/centos/7

Fedora 20: https://yum.dockerproject.org/repo/main/fedora/20

Fedora 21: https://yum.dockerproject.org/repo/main/fedora/21

Fedora 22: https://yum.dockerproject.org/repo/main/fedora/22

Now you can install the current Docker release.

$ sudo yum erase docker* # Remove obsolete versions
$ sudo yum install docker-engine
Tip

If you get a Cannot start container error, try running sudo yum upgrade selinux-policy and then reboot your system.

Warning

Older Fedora releases have a pre-existing package called docker, which is a KDE and GNOME2 system tray replacement docking application for WidowMaker. In newer versions of Fedora, this package has been renamed to wmdocker.

Mac OS X 10.10

To install Docker Machine on Mac OS X, you can use any one of the following methods, depending on your preferences and needs:

  • GUI Installer

  • Homebrew

New users may want to stick with the GUI installer for simplicity.

GUI installer

Download the latest Docker Toolbox installer and then double-click on the downloaded program icon. Follow all of the installer prompts until the installation is finished.

On Mac OS X, the Docker Toolbox includes Docker Client, Machine, Compose, and Kitematic.

You will also need to download and install VirtualBox, which Mac OS X requires to launch Linux virtual machines that can build Docker images and run containers.

Homebrew installation

To install using the popular Homebrew package management system for Mac OS X, you must first install Homebrew. The Homebrew project suggests installing the software with the following command:

$ ruby -e 
"$(curl -fsSL 
https://raw.githubusercontent.com/Homebrew/install/master/install)"
Caution

Running random scripts from the Internet on your system is not considered wise. It is unlikely that this script has been altered in a malicious manner, but a wise soul would read through the script first, or consider an alternative installation option.

If you already have Homebrew installed on your system, you should update it and all the installed formulas by running:

$ brew update

To install VirtualBox via Homebrew, you need to add support for an additional Homebrew repository that contains many GUI and large binary applications for Mac OS X. This can be done with one simple command:

$ brew install caskroom/cask/brew-cask
Note

You can find more information about Homebrew Casks at caskroom.io.

Now that you have Homebrew and Cask installed and the newest software formulas have been downloaded, you can install VirtualBox with the following command:

$ brew cask install virtualbox

And then installing Docker is as simple as running:

$ brew install docker
$ brew install docker-machine

Microsoft Windows 8

Download the latest Docker Toolbox installer and then double-click on the downloaded program icon. Follow all of the installer prompts until the installation is finished.

On Windows, the Docker Toolbox includes Docker Client, Machine, and Compose.

You will also need to download and install VirtualBox, which Mac OS X requires to launch Linux virtual machines that can build Docker images and run containers.

Note

Installation directions for additional operating systems can be found at docs.docker.com.

Docker Server

The Docker server is integrated into the same binary that you use as the client. It’s not obvious that it’s the same when you install it because all of the Linux init systems shield you from the command that is actually invoked to run the daemon. So it’s useful to see that running the Docker daemon manually on a Linux system is a simple as typing something like this:

$ sudo docker daemon -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
Note

In older versions of Docker, the server was started with docker -d or docker --daemon.

This command tells Docker to start in daemon mode (-d), create and listen to a Unix domain socket (-H unix:///var/run/docker.sock), and bind to all system IP addresses using the default unencrypted traffic port for docker (-H tcp://0.0.0.0:2375).

Note

If you already have Docker running, manually executing the daemon again, will fail because it can’t use the same ports twice.

Of course, you’re not likely to have to do this yourself. But that’s what going on behind the scene. On non-Linux systems, you will need to set up a Linux-based virtual machine to host the Docker server.

Systemd-Based Linux

Current Fedora releases utilize systemd to manage processes on the system. Because you have already installed Docker, you can ensure that the server starts every time you boot the system by typing:

$ sudo systemctl enable docker

This tells systemd to enable the docker service and start it when the system boots or switches into the default runlevel.

To start the docker server, type the following:

$ sudo systemctl start docker

Upstart-Based Linux

Ubuntu uses the upstart init daemon, although future versions are very likely going to be converting to systemd. Upstart replaces the traditional Unix init system with an event-driven model and supports vastly simplified init scripts, sometimes only a few lines long.

To enable the docker server to start when the system boots, type:

$ sudo update-rc.d docker.io defaults

To start the service immediately, you can use:

$ service docker.io start

init.d-Based Linux

Many Linux distributions used on production servers are still using a more traditional init.d system. If you are running something based on the Red Hat 6 ecosystem, among others, then you can likely use commands similar to the following to control when the docker server runs.

Enable the Docker service at boot with:

$ chkconfig docker on

Start the Docker service immediately:

$ service docker start

or:

$ /etc/init.d/docker start

Non-Linux VM-Based Server

If you are using Microsoft Windows or Mac OS X in your Docker workflow, you will need something like VirtualBox and Docker Machine, so that you can set up a Docker server for testing. These tools allow you to boot a Linux virtual machine on your local system. We’ll focus on Docker Machine because it’s more universal than other tools.

In addition to Docker Machine, it is also possible to use other tools to set up the Docker server, depending on your preferences and needs.

Docker Machine

In early 2015, Docker announced the beta release of Docker Machine, a tool that makes it much easier to set up Docker hosts on bare-metal, cloud, and virtual machine platforms.

The easiest way to install Docker Machine is to visit the GitHub releases page and download the correct binary for your operating system and architecture. Currently, there are variants for 32- and 64-bit versions of Linux, Windows, and Mac OS X.

For these demonstrations, you will also need to have a recent release of a hypervisor, like VirtualBox, installed on your system.

For this section, you will use a Unix-based system with VirtualBox for the examples.

First, you need to download and install the docker-machine executable. The example below downloads v0.6.0, but you can determine the current release on GitHub.

$ mkdir ~/bin
$ curl -L https://github.com/docker/machine/releases/
download/v0.6.0/docker-machine-`uname -s`-`uname -m` 
> ~/bin/docker-machine
$ export PATH=${PATH}:~/bin
$ chmod u+rx ~/bin/docker-machine
Tip

We’ve had to line-wrap the URL to fit the format of this book. If you have trouble running that in your shell as-is, try removing the backslashes and joining it into one line without any spaces in the URL.

Once you have the docker-machine executable in your path, you can start to use it to set up Docker hosts. Here we’ve just put it temporarily into your path. If you want to keep running it in the future, you’ll want to add it to your .profile or .bash_profile file. Now that we can run the tool, the next thing that you need to do is create a named Docker machine. You can do this using the docker-machine create command:

$ docker-machine create --driver virtualbox local
Running pre-create checks...
(local) ... Boot2Docker ISO is out-of-date, downloading the latest release...
(local) Latest release for github.com/boot2docker/boot2docker is v1.10.1
(local) Downloading ...boot2docker.iso from ...github.../boot2docker.iso...
(local) 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Creating machine...
(local) Copying .../cache/boot2docker.iso to .../local/boot2docker.iso...
(local) Creating VirtualBox VM...
(local) Creating SSH key...
(local) Starting the VM...
(local) Check network to re-create if needed...
(local) 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 local
Note

If you already have a docker-machine VM created, you can simply start it with the command: docker-machine start local.

This downloads a Boot2Docker image and then creates a VirtualBox virtual machine that you can use as a Docker host. If you look at the output from the create command, you will see that it instructs you to run the following command:

$ eval $(docker-machine env local)

This command has no output, so what does it do exactly? If you run it without eval and the surrounding $(), you will see that it sets a couple of environment variables in our current shell that tell the Docker client where to find the Docker server:

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

And now if you want to confirm what machines you have running, you can use the following command:

$ docker-machine ls
NAME  ACTIVE DRIVER     STATE   URL                     SWARM DOCKER  ERRORS
local *      virtualbox Running tcp://172.17.42.10:2376       v1.10.1

This tells you that you have one machine, named local, that is active and running.

Now you can pass commands to the new Docker machine by leveraging the regular docker command, since you have set the proper environment variables. If you did not want to set these environment variables, you could also use the docker and docker-machine commands in conjunction with one another, like so:

$ docker $(docker-machine config local) ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES

This command embeds the output from docker-machine into the middle of the docker command. If you run the docker-machine on its own, you can see what it is adding to the docker command:

$ docker-machine config local
--tlsverify
--tlscacert="/Users/me/.docker/machine/certs/ca.pem"
--tlscert="/Users/me/.docker/machine/certs/cert.pem"
--tlskey="/Users/me/.docker/machine/certs/key.pem"
-H=tcp://172.17.42.10:2376

Although you can see the Docker host’s IP address in the output, you can ask for it explicitly with the following command:

$ docker-machine ip local
172.17.42.10

If you want to log in to the system, you can easily do this by running:

$ docker-machine ssh local
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
                          __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___  __| | ___   ___| | _____ _ __
| '_  / _  / _ | __| __) / _` |/ _  / __| |/ / _  '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.10.1, build master : b03e158 - Thu Feb 11 ... UTC 2016
Docker version 1.10.1, build 9e83765
docker@local:~$ exit

To stop your Docker machine, you can run:

$ docker-machine stop local

And then you can run this to restart it (you need it to be running):

$ docker-machine start local
Stopping "local"...
Machine "local" was stopped.
Warning

Some of the documentation states that if you run docker-machine stop without specifying a machine name, the command will execute on the active machine as identified in the output of docker-machine ls. This does not seem to actually be the case with all releases of docker-machine.

If you want to explore the other options that docker-machine provides, you can simply run docker-machine without any other options to see the command help.

Boot2Docker

Note

Boot2Docker was officially deprecated by Docker with the release of Docker 1.8, and replaced with Docker Machine. It is still documented here, as some people prefer to use Boot2Docker for simple local development workflows. It is currently community-maintained, and new ISO images for the VM have been released.

To install Boot2Docker, download the version for your operating system from bbot2docker.io and run the installer, following all the prompts.

Once you have Boot2Docker installed you will need to initialize Boot2Docker and download the required boot image. You can do this, by running the following command the first time you use Boot2Docker. You should see output similar to what is displayed below.

$ boot2docker init

  WARNING: The 'boot2docker' command line interface (not to be confused with
  'boot2docker' the operating system) is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended ... method.

Latest release for github.com/boot2docker/boot2docker is v1.10.1
Downloading boot2docker ISO image...
Success: downloaded https://.../releases/download/v1.10.1/boot2docker.iso
  to /Users/me/.boot2docker/boot2docker.iso
Initialization of virtual machine "boot2docker-vm" complete.
Use `boot2docker up` to start it.

Now you can start up a virtual machine with a running Docker daemon. By default, Boot2Docker will map port 2376 on your local host to the secure Docker port 2376 on the virtual machine to make it easier to interact with the Docker server from your local system.

$ boot2docker up

  WARNING: The 'boot2docker' command line interface (not to be confused with
  'boot2docker' the operating system) is officially deprecated.

  Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

  Docker Toolbox (https://docker.com/toolbox) is the recommended ... method.

Waiting for VM and Docker daemon to start...
.........................ooooooooooooo
Started.
Writing /Users/me/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/me/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/me/.boot2docker/certs/boot2docker-vm/key.pem

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_HOST=tcp://172.17.42.10:2376
    export DOCKER_CERT_PATH=/Users/me/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

Or run: `eval "$(boot2docker shellinit)"`

To set up your shell environment so that you can easily use your local Docker client to talk to the Docker daemon on your virtual machine, you can run:

$ eval $(boot2docker shellinit)
Writing /Users/me/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/me/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/me/.boot2docker/certs/boot2docker-vm/key.pem

If everything is running properly, you should now be able to run the following to connect to the Docker daemon:

$ docker info
Containers: 0
Images: 0
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.17-boot2docker
Operating System: Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - ... 2016
CPUs: 8
Total Memory: 1.955 GiB
Name: boot2docker
ID: FZT2:SOXP:VWYZ:UAJO:PZV3:FTSD:E5I2:IFQP:2OU4:5NQH:YRXP:IOCF
Debug mode (server): true
File Descriptors: 10
Goroutines: 28
System Time: 2016-02-15T17:51:15.470080546Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Username: me
Registry: https://index.docker.io/v1/

To connect to a shell on your Boot2Docker-based virtual machine, you can use the following command:

$ boot2docker ssh
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
                          __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___  __| | ___   ___| | _____ _ __
| '_  / _  / _ | __| __) / _` |/ _  / __| |/ / _  '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.10.1, build master : b03e158 - Thu Feb 11 22:34:01 UTC 2016
Docker version 1.10.1, build 9e83765
docker@boot2docker:~$ exit

You can stop your Boot2Docker image by running:

$ boot2docker stop

Vagrant

If you need more flexibility with the way your Docker development environment is set up, you might want to consider using Vagrant instead of Docker Machine or Boot2Docker. Like Docker Machine, Vagrant provides support for multiple hypervisors, but it is much more extensible, and can often be leveraged to mimic even the most complex environments.

A common use case for leveraging Vagrant during Docker development is to support testing on images that match your production environment. Vagrant supports everything from broad distributions like CentOS 7 and Ubuntu 14.04, to finely focused atomic host distributions like CoreOS and Project Atomic.

Vagrant can be easily installed on most platforms by downloading a self-contained package from vagrantup.com. You will also need to have a hypervisor, like VirtualBox, installed on your system.

In the following example, you will create a CoreOS-based Docker host running the Docker daemon on the unencrypted port 2375. You could use your favorite distribution here instead, but CoreOS ships with working Docker out of the box and the image is quite small.

Note

In production, Docker should always be set up to only use encrypted remote connections. Although Docker Machine and Boot2Docker now use encrypted communications by default, setting up Vagrant to do this in CoreOS is currently a bit too complicated for this installation example.

After Vagrant is installed, create a host directory with a name similar to docker-host and then move into that directory:

$ mkdir docker-host
$ cd docker-host

To install the coreos-vagrant files, you need the version control tool named git. If you don’t already have git, you can download and install it from git-scm.com. When git is installed, you can grab the coreos-vagrant files and then change into the new directory with the following commands:

$ git clone https://github.com/coreos/coreos-vagrant.git
$ cd coreos-vagrant

Inside the coreos-vagrant directory, we need to create a new file called config.rb (that tells it to expose the Docker TCP port so we can connect):

echo "$expose_docker_tcp=2375" > config.rb

Next you’ll need to leverage the built-in cloud-init tool to add some systemd unit files that will enable the Docker daemon on TCP port 2375. You can do this by creating a file called user-data that contains all of the following, including #cloud-config at the beginning:

#cloud-config

coreos:
  units:
    - name: docker-tcp.socket
      command: start
      enable: yes
      content: |
        [Unit]
        Description=Docker Socket for the API

        [Socket]
        ListenStream=2375
        BindIPv6Only=both
        Service=docker.service

        [Install]
        WantedBy=sockets.target
    - name: enable-docker-tcp.service
      command: start
      content: |
        [Unit]
        Description=Enable the Docker Socket for the API

        [Service]
        Type=oneshot
        ExecStart=/usr/bin/systemctl enable docker-tcp.socket

When you have saved both of these files, you can start up the Vagrant-based virtual machine by running:

$ vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Box 'coreos-alpha' could not be found. Attempting to find and install...
    core-01: Box Provider: virtualbox
    core-01: Box Version: >= 308.0.1
==> core-01: Loading metadata ... 'http://.../coreos_production_vagrant.json'
    core-01: URL: http://.../coreos_production_vagrant.json
==> core-01: Adding box 'coreos-alpha' (v472.0.0) for provider: virtualbox
    core-01: Downloading: http://.../coreos_production_vagrant.box
    core-01: Calculating and comparing box checksum...
==> core-01: Successfully added box 'coreos-alpha' (v472.0.0) for 'virtualbox'!
==> core-01: Importing base box 'coreos-alpha'...
==> core-01: Matching MAC address for NAT networking...
==> core-01: Checking if box 'coreos-alpha' is up to date...
==> core-01: Setting the name of the VM: coreos-vagrant_core-01
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
    core-01: Adapter 1: nat
    core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
    core-01: 2375 => 2375 (adapter 1)
    core-01: 22 => 2222 (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
    core-01: SSH address: 127.0.0.1:2222
    core-01: SSH username: core
    core-01: SSH auth method: private key
    core-01: Warning: Connection timeout. Retrying...
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring network adapters within the VM...
==> core-01: Running provisioner: file...
==> core-01: Running provisioner: shell...
    core-01: Running: inline script

To set up your shell environment so that you can easily use your local Docker client to talk to the Docker daemon on your virtual machine, you can set the following variables:

$ unset DOCKER_TLS_VERIFY
$ unset DOCKER_CERT_PATH
$ export DOCKER_HOST=tcp://127.0.0.1:2375

If everything is running properly, you should now be able to run the following to connect to the Docker daemon:

$ docker info
Containers: 0
Images: 0
Storage Driver: btrfs
Execution Driver: native-0.2
Kernel Version: 3.16.2+
Operating System: CoreOS 472.0.0

To connect to a shell on the Vagrant-based virtual machine, you can run:

$ vagrant ssh
CoreOS (alpha)
core@core-01 ~ $ exit

You can stop your Vagrant-based VM by running:

$ vagrant halt

Test the Setup

You are now ready to test that everything is working. You should be able to run any one of the following commands on your local system to tell the Docker daemon to download the latest official container for that distribution and then launch it running an instance of bash.

This step is important to ensure that all the pieces are properly installed and communicating with each other as expected. It also shows off one of the features of Docker: we can run containers based on any distribution we like. In the next few steps we’ll run Docker containers based on Ubuntu, Fedora, and CentOS. You don’t need to run them all to prove that this works; running one of them will suffice.

Note

If you want to run these commands on the server, be sure that you prepend each docker command with sudo. Alternatively you could add your user to the docker group directly.

Ubuntu

$ docker run --rm -ti ubuntu:latest /bin/bash

Fedora

$ docker run --rm -ti fedora:latest /bin/bash

CentOS

$ docker run --rm -ti centos:latest /bin/bash
Note

ubuntu:latest, fedora:latest, and centos:latest all represent a Docker image name followed by an image tag.

Wrap-Up

Now that you have a running Docker setup, you can start to look at more than the basic mechanics of getting it installed. In the next chapter, you’ll explore some of the basic functionality of Docker with some hands-on work.

In the rest of the book, when you see docker on the command line, assume you will need to have the correct configuration in place either as environment variables or via the -H command-line flag to tell the docker client how to connect to your docker daemon.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.45.88