Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Docker Quick Start Guide
Docker Quick Start Guide

Docker Quick Start Guide: Learn Docker like a boss, and finally own your applications

eBook
$25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Docker Quick Start Guide

Setting up a Docker Development Environment

"Suddenly it occurred to me: Would it not be great if my trailer could simply be lifted up and placed on the ship without its contents being touched?"
- Malcolm McLean, American trucking entrepreneur

In this chapter, we are going to get everything set up for Docker development on our workstation. We will learn how to set up a Docker development environment on Linux, Windows, and OS X workstations. Then we will handle some post-installation steps for each OS. Lastly, we will learn how using Docker on each OS differs and what to watch out for between them.

By the end of this chapter, you will know the following:

  • How to set up your Docker development environment, irrespective of whether your workstation is running on the following:
    • CentOS
    • Ubuntu
    • Windows
    • OS X
  • The differences to be aware of when using Docker on different OSes

Technical requirements

You will need a development workstation using the OS of your choice, including Linux, Windows, or OS X. You will need sudo or admin access on the workstation. And since you will be installing Docker software that will be pulled from the internet, you will need basic internet connectivity on your workstation.

The code files of this chapter can be found on GitHub:

https://github.com/PacktPublishing/Docker-Quick-Start-Guide/tree/master/Chapter01

Check out the following video to see the code in action:
http://bit.ly/2rbGXqy

Setting up your Docker development environment

It's time to get our hands dirty. Let's dive in and set up our workstation. No matter what your preferred OS might be, there's a Docker for that. Using the following as a guide, we will walk you through the setup of Docker on your workstation. We can begin with setting up your Linux workstation, then we'll tackle a Windows system, and finish up with what is probably the most common developer option, the OS X workstation. While OS X may be the most popular developer option, I would recommend that you consider a Linux distribution for your workstation of choice. We'll talk more about why I make that recommendation later in the Installing Docker on an OS X workstation section. But for now, just pay close attention during the Linux install discussion in case you are persuaded to develop on Linux.

Generally speaking, there are two flavors of Docker to consider: Docker Enterprise Edition, or Docker EE, and Docker Community Edition, or Docker CE. Typically, in an enterprise, you would opt for the Enterprise Edition, especially for the production environments. It is intended for business-critical use cases, and Docker EE, as the name suggests, is certified, secured, and supported at an enterprise-grade level. It is a commercial solution that is supported by and purchased from Docker.

The other flavor, Docker CE, is a community-supported product. CE is available free and is often the choice for production environments of small businesses, and for developer workstations. Docker CE is a fully capable solution that allows the developer to create containers that can be shared with team members, used with automated build tools for CI/CD, and, if desired, shared with the Docker community at large. As such, it is the ideal option for a developer's workstation. It is worth noting that Docker CE has two release paths: stable and edge. We will be using the stable release path of Docker CE for all of the installation examples in this chapter.

We are going to start off the installation discussion with CentOS Linux, but feel free to skip ahead to the Ubuntu, Windows, or Mac section if you are in a hurry.

Installing Docker on a Linux workstation

We will be executing the Linux installation steps of Docker for both an RPM-based workstation (using CentOS) and a DEB-based workstation (using Ubuntu) so that you will have instructions that fit the Linux distribution that most closely matches what you are currently using, or plan on using at some point in the future. We will begin our installation journey with CentOS.

You can find all of the download links used in the installation of all OSes in the References section.

Installing Docker on a CentOS workstation

Docker CE for CentOS requires a maintained version of CentOS 7. Although installation may work on archived versions, they are neither tested nor supported.

There are three methods to install Docker CE on CentOS:

  • Via Docker repositories
  • Downloading and manually installing the RPMs
  • Running Docker's convenience scripts

The most common method used is via Docker repositories, so let's begin there.

Installing Docker CE via the Docker Repository

First, we will need to install some required packages. Open a terminal window and enter the following command:

# installing required packages
sudo yum install -y yum-utils \

device-mapper-persistent-data \
lvm2

This will make sure that we have both the yum-config-manager utility and the device mapper storage driver installed on the system. It is illustrated in the following screenshot:

Note that your installation of CentOS 7 may already have these installed, and in that case the yum install command will report that there is nothing to do.

Next, we will set up the CentOS stable repository for Docker CE.

It is worth noting that you will still need to set up the stable repository even if you want to install the edge releases.

Enter the following command to set up the stable repository:

# adding the docker-ce repo
sudo yum-config-manager \

--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

Optionally, if you want to use the edge release, you can enable it with the following command:

# enable edge releases
sudo yum-config-manager --enable docker-ce-edge

Similarly, you can disable access to the edge release with this command:

# disable edge releases
sudo yum-config-manager --disable docker-ce-edge

Now the fun begins... We are going to install Docker CE. To do so, enter the following command:

# install docker
sudo yum -y install docker-ce

If you get an error about the need to have container-selinux installed, use this command to install it, then try again:

# install container-selinux
sudo yum -y --enablerepo=rhui-REGION-
rhel-server-extras \
install container-
selinux

sudo yum -y install docker-ce

There you have it! Installing Docker CE was way easier than you thought it was going to be, right?

Let's use the most basic method to confirm a successful install, by issuing the version command.

This command validates that we installed Docker CE, and shows us what version of Docker was just installed. Enter the following command:

# validate install with version command
docker --version

The latest version of Docker CE, at the time of writing, is 18.03.1:

We have one more critical step. Although Docker CE is installed, the Docker daemon has not yet been started. To start it, we need to issue the following command:

# start docker deamon
sudo systemctl start docker

It should quietly start up, looking something like this:

We saw how to validate that Docker installed using the version command. That is a great quick test, but there is an easy way to confirm not just the install, but that everything started and is working as expected, which is by running our first Docker container.

Let's issue the following command to run the hello-world container:

# run a test container
sudo docker run hello-world

If all is well, you will see something like the following:

We've got Docker CE installed on our CentOS workstation, and it is already working and running containers. We are off to a great start. Now that we know how to do an install using the Docker repositories, let's have a look at how to manually install using a downloaded RPM.

Installing Docker CE manually using a downloaded RPM

Another way to install Docker CE is to use a downloaded RPM. This method involves downloading the Docker CE RPM for the version you wish to install. You need to browse to the Docker CE Stable RPM downloads site. The URL for this is https://download.docker.com/linux/centos/7/x86_64/stable/Packages:

Click on the version of Docker CE you want to download, and when prompted, tell your browser to save the file. Next, issue the yum install command, providing the path and filename for the downloaded RPM file. Your command should look something like this:

# install the docker rpm
sudo yum install ~/Downloads/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

You will need to start the Docker daemon. You'll use the preceding command in the repo section:

# start docker
sudo systemctl start docker

And, as we learned before, you can validate the functionality of your installation with the following commands:

# validate the install and functionality
docker --version

sudo docker run hello-world

While this method might seem simpler and easier to execute, it is less desirable because it is more of a manual process, especially when it comes time to update your version of Docker CE. You have to again browse to the downloads page, find the later version, download it, then do the yum install. Using the Docker Repository method described earlier, upgrades are as simple as issuing a yum upgrade command. Let's now take a look at one more method of installing Docker CE on your CentOS workstation.

Installing Docker CE by running convenience scripts

The third way to install Docker is to use the convenience scripts provided by Docker. The scripts allow you to install either the latest edge version or the latest test version of Docker. It is not recommended that either of these is used in a production environment, but they do serve a purpose for testing and developing the latest Docker versions. The scripts are somewhat limited in that they do not allow you to customize any options during the install. The same scripts can be used across a variety of Linux distributions as they determine the base distro you are running and then do the install based on that determination. The process is simple.

Use curl to pull down the desired script, and then use sudo to run the script.

The commands to run the latest edge version are as follows:

# download and run the install script
curl -fsSL get.docker.com -o get-docker.sh

sudo sh get-docker.sh

Executing the script will result in output that looks like the following:

The docker group has been created for you by the script, but since CentOS is RPM centric, you still need to start the Docker service yourself:

# start docker
sudo systemctl start docker
If this were a Debian-based system, the Docker service would have been started automatically by the script.

Now that we have examined the three ways to install Docker on your CentOS workstation, it is a good time to discuss a few additional steps that are recommended in your post-installation setup.

Post-install steps you might want to consider

All three of the install methods automatically create a docker group for you, but if you want to be able to run Docker commands without using root or sudo, then you will want to add your user to the docker group.

Be aware that many Docker commands require full admin access to execute, so adding a user to the docker group is comparable to granting them root access, and the security implications should be considered. If the user already has root access on their workstation, adding them to the docker group is only providing them a convenience.

Adding the current user to the docker group is easily accomplished with the following command:

# add the current user to the docker group
sudo usermod -aG docker $USER

You will need to log out and log back in to update the group memberships on your account, but once you have done that, you should be all set to execute any Docker commands without using sudo.

This can be validated by running the hello-world container without sudo:

# test that sudo is not needed
docker run hello-world

Next, you will want to configure your system to have the Docker service start on system-boot:

# configure docker to start on boot
sudo systemctl enable docker

Another post-install step you should consider is installing docker-compose.

This tool can be an important addition to your Docker tool belt and we will be discussing its use in Chapter 7, Docker Stacks. The command to install docker-compose is:

# install docker compose
sudo curl -L \
https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Congratulations, your CentOS workstation is now ready to start developing your Docker images and deploying your Docker containers. Next up, we will learn how to install Docker onto a DEB-based system using an Ubuntu workstation. If you're ready, read on.

Installing Docker on an Ubuntu workstation

As we did on the CentOS workstation, we are going to install Docker CE on our Ubuntu workstation. The requirement for installing Docker CE on Ubuntu is that you have to be running a 64-bit recent LTS release, such as Bionic, Xenial, or Trusty. You can install an edge version of Docker CE onto the Artful version of Ubuntu.

There are three methods to install Docker CE on Ubuntu:

  • Via Docker repositories
  • Downloading and manually installing the DEB packages
  • Running convenience scripts

The most common method used is via Docker repositories, so let's begin there.

Installing Docker CE via the Docker Repository

We need to set up the Docker repository first, and then we can do the installation, so let's take care of the repo now.

The first step will be to update the apt package index. Use the following command to do that:

# update apt-get libraries
sudo apt-get update

Now we need to install some supporting packages:

# install required packages
sudo apt-get install \

apt-transport-https \
ca-certificates \
curl \
software-properties-common

Next, we need to get the GPG key for Docker:

# get the GPG key for docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo apt-key add -

You can confirm that you have added Docker's GPG key successfully; it will have a fingerprint of 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.

You can verify the key by checking the last eight characters match 0EBFCD88 with this command:

# validating the docker GPG key is installed
sudo apt-key fingerprint 0EBFCD88

Finally, we need to actually set up the repository. We will be focusing on the stable repo for our examples.

If you want to install the edge or test versions of Docker CE, be sure to add the word edge or test after the word stable (do not replace the word stable) in the following command:

# adding the docker repository
sudo add-apt-repository \

"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

Now that our system is set up with the correct repository for installing Docker CE, let's install it.

Start by making sure that all of the packages are up to date by issuing the apt-get update command:

# update apt-get libraries again
sudo apt-get update

And now we will actually install Docker CE:

# install docker
sudo apt-get install docker-ce

Docker is installed. You can check the Docker version after the install to confirm a successful installation:

# validate install with version command
docker --version

The version command should look something like this:

Now, let's validate that the Docker installation is working as desired. To do this, we will run the hello-world Docker image using the following command:

# validating functionality by running a container
sudo docker run hello-world

Did you notice something interesting happened?

We did not have to start Docker after the installation as we did in the CentOS installation. That is because, on DEB-based Linux systems, the install process also starts Docker for us. Additionally, the Ubuntu workstation is configured to start Docker on boot. So both of the Docker start steps are handled for you during the installation. Nice! Your Ubuntu workstation now has Docker installed and we've verified it is working as desired.

Although using the Docker repository is the best way to install Docker on your workstation, let's take a quick look at another way to install Docker CE on an Ubuntu workstation, that being by manually installing it with a DEB package.

Installing Docker CE manually using a DEB package

Now we will show you how to download and install the Docker CE DEB package. You should consider using this method if, for whatever reason, the repositories are not available for your workstation.

You will need to download the Docker CE package, so start by opening your browser and going to the Ubuntu Docker CE packages download site at https://download.docker.com/linux/ubuntu/dists/.

There, you will find a list of Ubuntu version folders listed, which looks something like this:

You want to select the folder that matches the version of Ubuntu installed on your workstation, which in my case is the xenial folder.

Continue browsing to /pool/stable/ and then to the processor folder that matches your workstation hardware. For me that is amd64, and it looks like this:

Now click on the version of Docker CE you want to download and install.

Be sure to select the Save File option before you click OK.

Once the package has been downloaded to your workstation, to install it, just use the dpkg command for manually installing a package.

You provide the path and filename for the downloaded Docker CE package as a parameter to dpkg. Here is the command I used for the package that was just downloaded:

# installing docker package
sudo dpkg -i ~/Downloads/docker-ce_18.03.1~ce-0~ubuntu_amd64.deb

Executing the command looks like this:

Now that Docker is installed, let's use the version command to confirm successful install, and then run the hello-world container to validate that Docker is working as desired:

# validating the install and functionality
docker --version
sudo docker run hello-world

This is good. Just like the repository installation, your docker group has been created and both of the start steps are handled for you in the manual package installation. You do not have to start Docker, and you do not have to configure Docker to start on boot. So, you are ready to start creating Docker images and running Docker containers.

However, before we get going with creating and running, there is one more method of installing Docker on an Ubuntu workstation that we will cover. You can use Docker's convenience scripts to install the latest edge or test versions of Docker CE. Let's take a look at how to do that now.

Installing Docker CE by running convenience scripts

Another method of installing Docker is to use the convenience scripts provided by Docker. The scripts allow you to install either the latest edge version or the latest test version of Docker. It is not recommended that either of these is used in a production environment, however, they do serve a purpose for testing and developing the latest Docker versions. The scripts are somewhat limited in that they do not allow you to customize any options in the install. The same scripts can be used across a variety of Linux distributions as they determine the base distro you are running, and then do the install based on that determination. The process is simple. Use curl to pull down the desired script, and then use sudo to run the script. The commands to run the latest edge version are as follows.

Use the following command to install curl:

# install curl
sudo apt-get install curl

Now get the script and run the docker script to install:

# download and run the docker install script
curl -fsSL get.docker.com -o get-docker.sh

sudo sh get-docker.sh

Executing the script will result in output that looks like the following:

The docker group has been created for you by the script. The Docker service has been started, and the workstation has been configured to run Docker on boot. So, once again, you are ready to start using Docker.

We have examined the three ways to install Docker on your Ubuntu workstation, so now is a good time to discuss an additional step that is recommended for your post-installation setup.

Post-install steps you might want to consider

All three of these install methods automatically create a docker group for you, but if you want to be able to run Docker commands without using root or sudo, you will want to add your user to the docker group.

Be aware that many Docker commands require full admin access to execute, so adding a user to the docker group is comparable to granting them root access, and the security implications should be considered. If the user already has root access on their workstation, adding them to the docker group is only providing them a convenience.

Adding the current user to the docker group is easily accomplished with the following command:

# add the current user to the docker group
sudo usermod -aG docker $USER

You will need to log out and log back in to update the group memberships on your account, but once you have done that, you should be all set to execute any Docker commands without using sudo.

This can be validated with the hello-world container:

# validate that sudo is no longer needed
docker run hello-world

Another post-install step you should consider is installing docker-compose.

This tool can be an important addition to your Docker tool belt and we will be discussing its use in Chapter 7, Docker Stacks. The command to install docker-compose is:

# install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Congratulations, your Ubuntu workstation is now ready to start developing your Docker images and deploying your Docker containers. Next up, we will learn how to install Docker onto a Windows-based workstation. If you're ready, read on.

Installing Docker on a Windows workstation

The Windows version of Docker CE is compatible with Windows 10 Pro or Enterprise editions. Docker CE on Windows provides a complete Docker development solution by integrating with Windows Hyper-V virtualization and networking. Docker CE on Windows supports creating and running both Windows and Linux containers. Docker CE on Windows is available from the Docker store at https://store.docker.com/editions/community/docker-ce-desktop-windows.

You will need to log in to the Docker store to download the Docker CE for Windows installer, so if you don't already have an account, go ahead and create one now and then log in to it.

Be sure to save your Docker credentials securely as you will be using them a lot in the future.

After logging in, you should see the Get Docker download button. Click on the download button and allow the installer to download to your workstation. Once the installer has finished downloading, you can click the Run button to begin the installation. If you get the security check, confirm that you want to run the installer executable by clicking the Run button. If you have UAC enabled on your workstation, you may see the User Account Control warning asking you to confirm that you want to allow the Docker CE installer to make changes to your device. You have to check Yes to continue, so go ahead and click it now.

The Docker CE installer will run and it will begin downloading Docker. Once the Docker installation files have been successfully downloaded, the installer will ask you to confirm your desired configuration. The options here are few. It is my recommendation that you add the shortcut to the desktop and that you do not check the Use Windows containers instead of Linux containers option:

The installer will unpack the Docker CE files. When the files are unpacked, you will get the Installation succeeded notification. According to the current documentation, the installer will run Docker for you at the end of the installation. It has been my experience that it does not always happen. Be patient and give it time, but if it does not start that first time you may have to run Docker manually.

If you selected the configuration option to add a shortcut for Docker to your desktop, you will now be able to double-click that shortcut icon and start Docker for the first time.

Docker will run and you will get a Welcome screen that lets you know that Docker is up and running. It is recommended that you provide your Docker credentials and log in at this time.

Whenever Docker is running, you will see a whale icon in the taskbar notifications area. If you mouse over that icon, you can get the status of the Docker process. You will see such statuses as Docker is starting and Docker is running. You can right-click on the icon to bring up the Docker for Windows menu:

Once you have Docker running on your Windows workstation, you can open up a Windows PowerShell command window and start using Docker. To verify that the installation was completed successfully, open a PowerShell window and enter the version command. To confirm that Docker is working as desired, run the hello-world Docker container:

# validate install and functionality
docker --version

docker run hello-world

Your Windows 10 workstation is now set up to create Docker images and run Docker containers. Docker should also be configured to start up on boot so that when you need to reboot your workstation, it will start up automatically.

Be aware that using Docker CE on a Windows workstation is not exactly like using Docker CE on a Linux workstation. There is an additional layer of virtualization this is hidden behind the scenes. Docker is running a small Linux VM in Hyper-V and all of your Docker interactions are passed through, to, and from, this Linux VM. For most use cases, this is never going to present any issues, but it does affect performance. We will talk more about this in the Discovering the differences to watch out for between OSes section.

There is one more bit of setup that we want to take a look at, so if you are ready, jump right into the next section.

Post-install steps you might want to consider

Here are a couple of post-install steps I recommend for your Docker Windows workstation.

Installing Kitematic

The Windows installation of Docker CE integrates with a graphical user interface tool called Kitematic. If you are a graphical interface kind of person (and since you are using Windows for Docker, I will guess that you are), you will want to install this tool.

Find the Docker icon in the taskbar notifications area and right-click on it to bring up the Docker for Windows menu. Click on the Kitematic menu option. Kitematic is not installed by default. You have to download the archive that contains the application. When you click the Kitematic menu option for the first time, you will be prompted to download it. Click the Download button, and save the archive file to your workstation:

You will need to unzip the Kitematic archive to use it. The uncompressed Kitematic folder needs to be in the C:\Program Files\Docker folder with a folder name of Kitematic for the Docker submenu integration to work correctly. Once you have Kitematic installed in the correct path on your Windows workstation, you can right-click the Docker icon in the task bar notifications area and select the Kitematic option again.

You will be prompted to enter your Docker credentials again to connect to Docker Hub. You can skip this step, but it is my recommendation that you go ahead and log in now. Once you log in (or skip the login step), you will see the Kitematic user interface. It allows you to download and run Docker containers on your workstation. Go ahead and try one, such as the hello-world-nginx container, or if you want to play a game, try the Minecraft container.

You are now ready to create Docker images and run Docker containers in your Windows 10 workstation, but we have one more workstation OS to learn how to install Docker CE on. Let's look at installing it on an OS X workstation next.

Setting up DockerCompletion for PowerShell

If you have ever used command-line completion, you will want to consider installing DockerCompletion for PowerShell. This tool provides command-line completion for Docker commands. It is fairly easy to install. You will need your system set up to allow the execution of the downloaded module. To do this, open a PowerShell command window with Run as Administrator, and issue the following command:

# allow remote signed scripts to run
Set-ExecutionPolicy RemoteSigned

You can now close the Administrator command window and open a normal user PowerShell command window. To install the DockerCompletion module, issue this command:

# install Docker completion
Install-Module DockerCompletion -Scope CurrentUser

And finally, to activate the module in your current PowerShell window, use this command:

# enable Docker completion
Import-Module DockerCompletion

Now you can use the features of command completion for all your Docker commands. This is a great keystroke saver!

Note that the Import-Module command is only active in the current PowerShell command window. If you want to have it available to all future PowerShell sessions, you will need to add the Import-Module DockerCompletion to your PowerShell profile.

You can easily edit your PowerShell profile (or create a new one if you haven't already) with this command:

# update your user profile to enable docker completion for every PowerShell command prompt
notepad $PROFILE

Enter the Import-Module DockerCompletion command and save the profile. Now your Docker command-line completion feature will be active in all future PowerShell sessions.

Installing Docker on an OS X workstation

The story for Docker on Mac has advanced a lot in recent years, and it is now a real, usable development solution for your Mac workstation. Docker CE for Mac requires OS X El Capitan 10.11 or newer macOS releases. The Docker CE app integrates with the hypervisor, network, and filesystem built into OS X. The installation process is simple: download the Docker installer image and launch it. You can download the installer image from the Docker store. You must log in to the Docker store be able to download the install image, so, create an account there if you don't have one already.

Be sure to save your credentials securely as you will need them later.

Browse to the Docker store page for Docker CE for Mac at https://store.docker.com/editions/community/docker-ce-desktop-mac. Remember that you must log into the Docker store to be able to download the installer image.

Once logged in to the Docker store, the Get Docker button will be available to click. Go ahead and click on it to start the download. The Docker CE for Mac install image may take some time to download. When the download has completed, double-click on the Docker.dmg image file to mount and open it:

Once the Docker CE for Mac image has mounted and opened, click the Docker icon and drag it onto the Applications icon to complete the install. The copying Docker to Applications action will be initiated. And when the copy process completes, the Docker application will be available to run from your Applications folder. Double-click on your Docker icon to launch it. Launching Docker for the first time will caution you that you are running an application downloaded from the internet to make sure you really want to open it. When the Docker app opens, you will be greeted with a friendly Welcome to Docker message.

Clicking next on the welcome message will warn you that Docker requires elevated privileges to run and will inform you that you must provide your credentials to install Docker's networking and app links. Enter your username and password. The Docker application will launch, adding a whale icon to the menu-notification area.

You will also be prompted to enter Docker store credentials to allow Docker for Mac to log in to the store. Enter your credentials and click on the Log In button. You will get a confirmation showing that you are currently logged in.

To validate that our installation was successful and confirm the functionality of our installation, we will issue the version command and then run Docker's hello-world container:

# validate install and functionality
docker --version

docker run hello-world

Your macOS workstation is now set up to create Docker images and run Docker containers. You are ready to containerize your apps! You can easily use your terminal window for all of your Docker work, but you may be interested in the graphical UI tool that is available for Mac, called Kitematic. Let's install Kitematic next.

Post-install steps you might want to consider

Here are a couple of post-install steps I recommend for your Docker OS X workstation.

Installing Kitematic

Although you can use the Docker CLI in your OS X terminal window, and probably will do so for most of your Docker development work, you have the option of using a graphical UI tool called Kitematic instead. To install Kitematic, right-click on the whale icon in the OS X menu-notification area to open the Docker for Mac menu. Click on the Kitematic menu option to download (and later to run) the Kitematic application. If you have not yet installed Kitematic, when you click on the Docker for Mac menu for it, you will be shown a message that includes a download link. The message also reminds you that you must install Kitematic into your Applications folder to enable Docker menu-integration. Click the here link to download the Kitematic application:

Once the download completes, move the downloaded application into your Applications folder, as directed earlier. Then, using the Docker for Mac menu, click on the Kitematic menu option again. This time it will run the Kitematic application. The first time you run the application, you will get the standard warning that you are running something that has been downloaded from the internet, asking if you really want to open it. Click on the Open button to do so.

Once you have Kitematic installed on your Mac workstation, you can click the Docker whale icon in the menu bar notifications area and select the Kitematic option again.

You will be prompted to enter your Docker credentials to connect Kitematic to Docker Hub. You can skip this step, but it is my recommendation that you go ahead and log in now. Once you log in (or skip the login step), you will see the Kitematic user interface. This allows you to download and run Docker containers on your workstation. Go ahead and try one, such as the hello-world-nginx container, or if you want to play a game, try the Minecraft container.

Congratulations! You are now set up to use both the Docker CLI and the Kitematic graphical UI to run your Docker containers and manage your Docker images. However, you will do your Docker image creation using the OS X terminal and your favorite code editor.

Installing Docker command-line completion

Install Homebrew. You may (probably) already have Homebrew installed on your Mac, but if not, you should install it now. Here is the command to install it:

# install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, use Homebrew to install bash-completion. Here is the command:

# use homebrew to install bash completion 
brew install bash-completion

The installation of bash-completion will instruct you to add the following line to your ~/.bash_profile file:

# update the bash profile to enable bash completion for every terminal session 
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

Now, create the links necessary to enable the Docker command-line completion feature. There is one link for each of the Docker toolsets. Here are the link commands for bash (if you use zsh, check the next code block for the link commands):

# create links for bash shell
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion $(brew --prefix)/etc/bash_completion.d/docker
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-machine
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-compose

Note that if you are using zsh instead of bash, the link commands are different. Here are the link commands for zsh:

# create links for zsh shell
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion /usr/local/share/zsh/site-functions/_docker
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.zsh-completion /usr/local/share/zsh/site-functions/_docker-machine
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.zsh-completion /usr/local/share/zsh/site-functions/_docker-compose

Finally, restart your terminal session—you can now use Docker command completion! Try it by typing docker and hitting the Tab key twice.

References

What differences to watch out for between OSes

Docker images, by design, are self-contained packages that include everything needed to run the application they are designed to execute. One of the great strengths of Docker is that Docker images can be run on almost any operating system. That being said, there are some differences in the experience of running Docker images on different OSes. Docker was created on Linux and is deeply integrated with some key Linux constructs. So, as you would expect, when you run Docker on Linux, everything integrates directly and seamlessly with the OS. Docker leverages the Linux kernel and filesystem natively.

Unfortunately, when you run Docker for Windows or Docker for Mac, Docker cannot leverage the same constructs that it does natively on Linux because they just do not exist on these other OSes. Docker handles this by creating a small, efficient Linux VM in a hypervisor for the non-Linux OS. With Docker for Windows, this Linux VM is created in Hyper-V. On macOS, the VM is created in a custom hypervisor, called hyperkit.

As you might expect, there is a performance overhead associated with the helper VMs. However, if you do use Windows or OS X for your development workstation, you will be pleased to know that Docker has made a lot of positive strides on both platforms, reducing the overhead and improving performance significantly with each new major version released. There are a lot of reports of high CPU utilization for the hyperkit hypervisor on OS X, but I have not personally experienced the issue. With the current stable versions of Docker CE, I believe that both Windows and OS X can be successfully used for Docker development.

Still, there are other differences, besides processing performance, to consider. There are two that you should be aware of: file mounts and endpoints.

Docker CE on a Linux OS is able to directly use the filesystem for its file mounts in the running containers—this provides native-disk-performance levels. You also can change the filesystem drivers used to achieve different levels of performance. This is not available for Docker on Windows or Docker on Mac. For both Windows and OS X, there is an additional filesystem tool that handles the file mounts. On Windows, you will be using Windows shared files, and on OS X it is osxfs. Unfortunately for the Windows and OS X users, the performance hit on the file mounts is significant. Even though Docker has made leaps and bounds in improving the file mount story for Windows and for OS X with version 17 and later, both are still measurably slower compared to running natively on a Linux OS. For Windows specifically, the file mount options are very restrictive. If you are developing an application that is disk-utilization heavy, this difference might be enough to have you immediately consider switching to a Linux development workstation.

One other area that differs between Docker on Linux and Docker for Windows or Docker for Mac is the utilization of endpoint ports. One example is with Docker for Windows; you are not able to access a container's endpoint from its the host using localhost. This is a known bug, but the only workaround is to access your container's endpoints from a different host than you are running them on. With Docker for Mac, there are other endpoint limitations, such as not being able to ping a container (because Docker for Mac cannot route the ping traffic to and from the container) and you cannot have per-container IP addressing (because the Docker bridge network is not reachable from macOS).

Any of these limitations might be enough for you to consider switching your development workstation to an Ubuntu or CentOS operating system. It was for me, and you will find that most of the examples found in this book will be executed on my Ubuntu workstation. I will try to point out any areas that may be significantly different if you are using Windows or OS X.

Summary

Wow! We covered a lot in this first chapter. You should now be able to install Docker on your workstation, regardless of the OS that it is running. You should be able to install Docker onto a Linux workstation using three different methods, and know some of the differences between installing on an RPM-based system and a DEB-based system.

We also covered some very significant reasons why you might consider using a Linux workstation for your development, instead of using a Windows or macOS workstation. And by now, you should be able to easily validate the successful installation of Docker by checking the version of Docker installed.

You should be able to easily confirm that Docker is working as desired by running a hello-world container. Not bad for your first chapter, right? Well, with this foundation, and your newly Docker-ready workstation, let's move right into Chapter 2, Learning Docker Commands, where we will learn about many Docker commands you'll use every day.

References

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn Docker installation on different types of OS
  • Get started with developing Docker images
  • Use Docker with your Jenkins CI/CD system

Description

Docker is an open source software platform that helps you with creating, deploying, and running your applications using containers. This book is your ideal introduction to Docker and containerization. You will learn how to set up a Docker development environment on a Linux, Mac, or Windows workstation, and learn your way around all the commands to run and manage your Docker images and containers. You will explore the Dockerfile and learn how to build your own enterprise-grade Docker images. Then you will learn about Docker networks, Docker swarm, and Docker volumes, and how to use these features with Docker stacks in order to define, deploy, and maintain highly-scalable, fault-tolerant multi-container applications. Finally, you will learn how to leverage Docker with Jenkins to automate the building of Docker images and the deployment of Docker containers. By the end of this book, you will be well prepared when it comes to using Docker for your next project.

Who is this book for?

This guide is for anyone who needs to make a quick decision about using Docker for their next project. It is for developers who want to get started using Docker right away.

What you will learn

  • Set up your Docker workstation on various platforms
  • Utilize a number of Docker commands with parameters
  • Create Docker images using Dockerfiles
  • Learn how to create and use Docker volumes
  • Deploy multi-node Docker swarm infrastructure
  • Create and use Docker local and remote networks
  • Deploy multi-container applications that are HA and FT
  • Use Jenkins to build and deploy Docker images

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 29, 2018
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781789347326
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 29, 2018
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781789347326
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Mastering Docker
$54.99
Docker Cookbook
$48.99
Docker Quick Start Guide
$32.99
Total $ 136.97 Stars icon

Table of Contents

9 Chapters
Setting up a Docker Development Environment Chevron down icon Chevron up icon
Learning Docker Commands Chevron down icon Chevron up icon
Creating Docker Images Chevron down icon Chevron up icon
Docker Volumes Chevron down icon Chevron up icon
Docker Swarm Chevron down icon Chevron up icon
Docker Networking Chevron down icon Chevron up icon
Docker Stacks Chevron down icon Chevron up icon
Docker and Jenkins Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(12 Ratings)
5 star 91.7%
4 star 0%
3 star 0%
2 star 0%
1 star 8.3%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Oct 20, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's easy follow. and very good to practice basic.
Amazon Verified review Amazon
JK Mar 23, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is down to earth and full of actually executable commands with output screen shots. No fluff. I have just started using Docker at work for containerizing apps for K8s, and I could use this book back and forth to see if what I am doing is correct. In fact I learnt k8s pv and pvc concepts easily from reading chapter 4 of this book 'Docker Volumes'.Chapter 5 & 7 I did not use much because I am already on k8s and I did not go deeper into Chapter 6 because I am not a networking guy. The last chapter 'Docker and Jenkins', I am yet to read but it is not a top priority thing for me as our DevOps/CICD teams take care of that. I am a developer and all that I wanted I got from Chapters 1 to 4. Chapter 3 'Creating Docker Images' specifically is a power packed one.I would definitely say, one can buy this book blindly, if you are really interested in hands on docker learning.Thanks Mr.Earl Waud, Great Book!
Amazon Verified review Amazon
MM Oct 12, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
He is a best writer . Make the concept very easy. He wrote it with easy English and very organized way. I made my concept clear in a single read. He is super Genius writer. He knows about the reader's mind. He also knows how to make easy of any hard concept.
Amazon Verified review Amazon
Marjan Khan Jan 15, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is an invaluable resource to get up to speed with containers. I have been working with VMware for the past 10 years, but more and more I am seeing containers take hold in the provisioning of software. I knew of containers to the extend that I could download a container and use what it offered, but did not really know how to build my own let alone persist changes, mount volumes, and setup networking.I recently had to build a custom tool to aid in a migration and rather than reach to building a dedicated VM, I opted to build it in a docker container. Not only was I able to iterate over multiple revisions of the tool quickly, but I also found that deploying into production was far easier, faster, and more secure thanks to the far smaller footprint containers offered. Without the aid of this book I am sure that I would have spent a lot more time in this endeavor and may have just opted to using a VM. I am very glad I did not :) I have found this book to be a great resource, clearly explaining all of the aspects of docker containers that I needed to kickstart my journey into the world of Docker, and I am sure you will too. ( Two Thumbs Up !! )
Amazon Verified review Amazon
Ben Weston Apr 07, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
At just 214 pages (including index) you wouldn't expect much from such a small book except perhaps a high level overview of the topics. However this is not the case. The book is absolutely packed with good information and doesn't waste a single page. Starting with initial setup & basic commands, you'll be shown best practice methods on how to create & manage containers using Docker, but it goes far deeper than that. Advanced concepts such as practical & easy to follow examples on third-party (remote) network drivers are explored. There is a LOT of information to take in for such a small book, so if you're looking for the maximum amount of info for the best value & smallest footprint I highly recommend this.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.