Home Virtualization-and-cloud Docker Bootcamp

Docker Bootcamp

By Russ McKendrick , Pethuru Raj , Jeeva S. Chelladhurai and 1 more
books-svg-icon Book
Subscription
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
Subscription
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book

Docker allows you to create a robust and resilient environment to generate portable, composable, scalable, and stable application containers.

The book starts by installing the core Docker Engine on MacOS, Windows 10 and Linux desktops. We will then define multi-container applications and understand the advantages of using containers locally. Once this is done, we will deploy containers on a single Docker host which is publicly accessible. Furthermore, we will learn how to deploy and configure a Docker Swarm cluster and explore networking and storage third-party plugins to extend the core Docker functionality. Towards the end, the book will demonstrate how to monitor and troubleshoot day-to-day problems in addition to various real world examples of container deployments.

Publication date:
April 2017
Publisher
Packt
Pages
196
ISBN
9781787286986

 

Chapter 1. Installing Docker Locally

In this, the first chapter, we are going to look at installing and configuring Docker on the following platforms:

  • macOS Sierra

  • Windows 10 Professional

  • Ubuntu 16.04 LTS Desktop

Once installed, we will then look at how you can interact with your local Docker installation.

Before we start our installation, I would like to take a moment to quickly talk about the version of Docker which we will be installing.

At the time of writing, Docker 17.03 has just been released and like most updates, introduces new features as well as changes to existing features. This book has been written with this version of Docker so some of the commands listed may not work or have the same effect when using older versions.

If you already have Docker installed, I would recommend that you check that you are running Docker 17.03 by running the following command:

docker version

If your version of Docker is older that 17.03 then please refer to the upgrade instructions in each of the following sections before proceeding with the rest of the chapters.

 

Docker for Mac and Windows


As we have already touched upon in the preface, the version of the Docker Engine we are going to be covering in this book is very much a Linux-based tool, so how does it work on macOS and Windows?

It is easy to assume that because macOS is an operating system built on-top of a UNIX like kernel called XNU that Docker will just run as it would do on a Linux machine, unfortunately, a lot of the features which allow Docker to run are not present in the Kernel used by macOS.

While there is the recently launched Windows Subsystem for Linux which is currently in beta, Docker for Windows does not currently take advantage of this, meaning that there is even less of a Linux-like kernel for Docker to use.

Note

The Windows Subsystem for Linux exposes an Ubuntu shell which allows you to run native Linux command-line tools on your Windows installation; for more information, please see https://msdn.microsoft.com/en-gb/commandline/wsl/about.

So how does Docker for Mac and Windows work? The latest versions of macOS and Windows 10 Professional ship with hypervisors which are built into the operating systems kernel, macOS has Hypervisor framework while Windows 10 uses Hyper-V.

Note

Hypervisor framework allows developers to build applications without the need to install third-party kernel extensions, meaning they can leverage full hardware virtualization but remain purely in user space meaning that virtual machines remain sandboxed as if they were running as a native application. The following URL gives a technical overview: https://developer.apple.com/reference/hypervisor

For Docker for Mac Docker have built their own open source framework which works with the Hypervisor framework called HyperKit: you can find out more about HyperKit at https://github.com/docker/HyperKit/.

Hyper-V has been the native hypervisor for Windows-based operating systems since Windows Server 2008; it has also been part of the desktop version of Windows since Windows 8 (Professional and Enterprise editions), it allows users and developers to launch Windows and Linux virtual machines with hardware virtualization in a sandboxed environment. For more information on Hyper-V, please see https://www.microsoft.com/en-us/cloud-platform/server-virtualization.

Docker for Mac and Windows uses these native virtualisation technologies to launch a virtual machine running their MobyLinux distribution, MobyLinux is a light-weight distribution based on Alpine Linux who's only function is to run Docker.

Note

The ISO for Alpine Linux currently weighs in at 26 MB, and a fully functioning minimal installation requires a footprint of ~130MB, while the distribution is extremely small it is as useable and secure as more common Linux distributions. You can find out more at https://alpinelinux.org/.

Docker for Mac and Windows takes care of launching, configuring, and maintaining the virtual machine as well as functions such as networking and mounting filesystems from your local machine to a MobyLinux virtual machine.

Docker for Mac

Docker for Mac has the following system requirements; if your machine does not meet them then Docker for Mac will fail to install:

  • Your Mac must be a 2010 or later model, with support for Intel's hardware support for memory man agement unit (MMU) virtualization.

  • You must be running OS X El Capitan 10.11 or newer. I recommend that you are running the latest macOS.

  • You must have at least 4GB of RAM.

  • Versions of VirtualBox 4.3.30 or lower must NOT be installed as this causes problems with Docker for Mac.

To check that your machine can support Docker for Mac you can run the following command:

sysctl kern.hv_support

This should return a 1 when you run the command; this means the virtualization is enabled in your kernel as it is available on your CPU.

Downloading Docker for Mac

Docker for Mac is available from the following URL:

https://store.docker.com/editions/community/docker-ce-desktop-mac

I would recommend sticking with the Stable channel for now as this is the version we will be installing on remote machines in later chapters. Clicking on Get Docker for Mac (stable) will kick off a download of a disk image (DMG) file, once downloaded double-click on the file to mount it.

Installing Docker for Mac

Like most macOS apps, all you have to do is the following:

  1. Drag the Docker application from the mounted disc image to your applications folder; opening the mounted image in the macOS finder by double clicking on it makes this task easy, as you can see from the following screenshot:

  2. Once the application has been copied, you can close the finder window and open your Applications, find Docker, and open it:

  3. When you open Docker for the first time you will be walked through the initial installation:

  4. Clicking Next will tell you that Docker will ask for your password, it needs this to complete the installation.

  5. After clicking OK and entering your password when prompted a whale icon will appear in the menu bar, and while Docker starts you should see something which looks like the following popup:

  6. Clicking Got it! will close the pop-up. You can tell that Docker has started as the small boxes on the whales back in the icon will stop animating; also left-clicking over the icon will bring up a menu which shows the status of your Docker installation:

  7. Selecting About Docker from the menu will open the following window:

  8. Running the following command in a terminal shows additional information about your Docker installation:

    docker version

    You should see something like the following output:

As you can see, it gives details on the Docker client which is installed on your macOS host and the MobyLinux virtual machine the client is connecting to.

Docker for Windows

Docker for Windows has the following system requirements; if your machine does not meet them then Docker for Windows will inform you before exiting:

  • You must be running a 64bit Windows 10 Pro, Enterprise and Education (1511 November update, build 10586 or later) installation or later (there are plans to support other versions in the future)

  • Hyper-V must be enabled, though the installer will enable it for you if needed

  • You must have at least 4GB of RAM

Downloading Docker for Windows

Docker for Windows is available from the following URL:

https://store.docker.com/editions/community/docker-ce-desktop-windows

Like Docker for Mac, I would recommend sticking with the Stable channel. Clicking on Get Docker for Windows (stable) will download an installer; once the installer has finished downloading, you will be given the option to Run it.

Installing Docker for Windows

When the Docker for Windows installer first opens, you will be greeted by the Docker License Agreement:

Clicking I accept the terms of the License Agreement will enable the Install button, clicking Install with immediately start the installation.

After a minute or two, you should receive confirmation that the installation has been completed.

Making sure that Launch Docker is ticked (it should be by default), click on Finish to open Docker. If you do not have Hyper-V enabled, then you will receive the following prompt:

Clicking Ok will reboot your computer so ensure that you have saved any open documents you may have. Once rebooted, Docker should launch automatically, and like Docker for Mac, you will notice that there is an icon of a whale in your menu bar:

Once Docker has started, selecting About Docker from the menu will open the following window:

Finally, open Windows PowerShell and entering the following command:

docker version

This will return similar information on Docker for Mac, showing both the client information and details on the MobyLinux virtual machine:

There is one more thing with Docker for Windows: you can run native Windows containers. You can enable this feature by selecting the Switch to Windows containers … option from the menu; if it is your first time enabling this feature then you will get the following dialog popup:

Clicking Ok will reboot your machine. Once rebooted, selecting the menu option again will switch you over from using Linux to Windows; this is reflected when you run the following:

docker version

As you can see, the server OS/Arch has changed from linux/amd64 to windows/amd64. We will not be looking at Windows containers in this book; you can change back to Linux containers by using the menu option:

Tip

If you have any problems running the commands in later chapters on Docker for Windows, check that you are using Linux containers by running docker version or using the menu.

Upgrading Docker for Mac and Windows

Both Docker for Mac and Windows allow you to easily update your installed version of Docker. If you have an old version of Docker for Mac or Windows installed, you should have been prompted that there is a later version of Docker available when you first open Docker. I you haven't had a prompt then selecting Check for Updates… from the menu will kick off the upgrade process, which is similar to the installation process we have already covered for each of the versions.

If there are no updates, then you will receive a notification confirming you are on the latest version.

 

Docker on Ubuntu 16.04


If you have been looking at the Docker website, you will notice that there is not a Docker for Linux Desktop download, that is because there is no need for one. Docker is a Linux tool and will run natively on most Linux desktops and servers.

While Docker is available in the main Ubuntu repositories, I would recommend installing Docker using the official repository. You can do this by running the following command:

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

This will configure and install the latest version of Docker Engine. Once installed, you will receive a command to run to give your user permission to run Docker, run the command and then log out.

When you log back in, you will be able to run the following command:

docker version

You should see something like the following:

Note

One thing I haven't mentioned so far is that when we installed Docker for Mac and Windows two additional components were installed. These were Docker Machine and Docker Compose, we will be covering these in Chapter 2, Launching Applications Using Docker and Chapter 3, Docker in the Cloud.

To install Docker Machine run the following commands:

curl -L "https://github.com/docker/machine/releases/download/v0.9.0/docker-machine-$(uname -s)-$(uname -m)" -o /
tmp/docker-machine
chmod +x /tmp/docker-machine
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

To install Docker Compose, run the following commands:

curl -L "https://github.com/docker/compose/releases/download/1.
10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /tmp/docker-compose
sudo cp /tmp/docker-compose /usr/local/bin/docker-compose

Once installed you should be able to run the following two commands:

docker-compose version
docker-machine version
 

Testing your installation


Now that we have Docker installed, we are going to quickly test our installation by downloading, running and connecting to a NGINX container.

Note

NGINX is a free, open source, high-performance HTTP server and reverse proxy. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Tip

A note on Docker commands

Docker 1.13 introduced a slightly altered set of command line instructions for interacting with containers and images. As this syntax will eventually become the new standard we will be using it throughout this book. For more information on the CLI restructure, please see the Docker 1.13 announcement blog post at https://blog.docker.com/2017/01/whats-new-in-docker-1-13/

To download and launch the container all you need to do run the following commands from your terminal prompt;

docker image pull nginx
docker container run -d --name nginx-test -p 8080:80 nginx

The first command pulls the NGINX container image from the Docker Hub, and the second command launches our NGINX container, naming it nginx-test mapping port 8080 on your machine to port 80 on the container.

You can check that the container is running using the following command:

docker container ps

Opening your browser and going to http://localhost:8080/ should show you the default Welcome to NGINX page.

As you can see from the following screens, the process is the same when using Docker for Mac:

Docker for Windows:

Or Docker on Ubuntu 16.04:

As you can see from the screens above, the result of us running the same command on each of the three platforms is exactly the same.

Once you have tested launching a container you can tidy up afterwards by running the following commands to stop and remove the container and then delete the image:

docker container stop nginx-test
docker container rm nginx-test
docker image rm nginx
 

Summary


In this chapter, we have worked through installing Docker for Mac, Docker for Windows and Docker on Ubuntu 16.04. Hopefully, you will have followed along with one or more of the installations on your local machine. We have also launched our first container and connected to it using our web browser.

In the next chapter, we will go into a lot more detail on the commands we used to launch our test container as well as using Docker Compose to launch multi-container applications.

About the Authors
  • Russ McKendrick

    Russ McKendrick is an experienced system administrator who has been working in IT and related industries for over 25 years. During his career, he has had varied responsibilities, from looking after an entire IT infrastructure to providing first-line, second-line, and senior support in both client-facing and internal teams for large organizations.

    Russ supports open source systems and tools on public and private clouds at N4Stack, a Node4 company, where he is the practice manager (SRE and DevOps). In his spare time, he has written several books including Mastering Docker, Learn Ansible and Kubernetes for Serverless Applications, all published by Packt Publishing.

    Browse publications by this author
  • Pethuru Raj

    Pethuru Raj (PhD) works as the chief architect at the Site Reliability Engineering Center of Excellence, Reliance Jio Infocomm Ltd. (RJIL), Bengaluru. Previously, he worked as a cloud infrastructure architect at the IBM Global Cloud Center of Excellence, IBM India, Bengaluru. He also had an extended stint as a TOGAF-certified enterprise architecture consultant in Wipro Consulting's services division and as a lead architect in the corporate research division of Robert Bosch, Bengaluru. He has more than 17 years of IT industry experience and 8 years' research experience.

    Browse publications by this author
  • Jeeva S. Chelladhurai

    Jeeva S. Chelladhurai has been working as a DevOps specialist at the IBM Global Cloud Center of Excellence (CoE) in India for the past 8 years. He has more than 20 years of experience in the IT industry. In various capacities, he has technically managed and mentored diverse teams across the globe in envisaging and building pioneering telecommunication products. He specializes in DevOps and cloud solution delivery, with a focus on data center optimization, software-defined environments (SDEs), and distributed application development, deployment, and delivery using the newest Docker technology. Jeeva is also a strong proponent of agile methodologies, DevOps, and IT automation. He holds a master's degree in computer science from Manonmaniam Sundaranar University and a graduate certificate in project management from Boston University. He has been instrumental in crafting reusable assets for IBM solution architects and consultants in Docker-inspired containerization technology.

    Browse publications by this author
  • Vinod Singh

    Vinod Singh held various positions across development, architecture, and engagement with clients throughout his career.

    Currently, he is a senior cloud architect with IBM's cloud flagship offering Bluemix, supporting customers across the world. Vinod's experience with networking and data communication spans software design, development, and testing. The cloud, cognitive computing, and Linux are his passions, and he feels cognitive computing is once again going to change the world.

    Vinod is a regular speaker at IBM's internal conferences, IEEE conferences, and technology meetups. Vinod's latest day job revolves around IBM Bluemix, Kubernetes, Docker, IBM Watson and Amazon AWS.

    Browse publications by this author
Latest Reviews (2 reviews total)
It's quite good for the basis. I wish it dug deeper in the examples.
Excelente Material sobre docker
Docker Bootcamp
Unlock this book and the full library FREE for 7 days
Start now