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

You're reading from   Docker Quick Start Guide Learn Docker like a boss, and finally own your applications

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789347326
Length 230 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Earl Waud Earl Waud
Author Profile Icon Earl Waud
Earl Waud
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Setting up a Docker Development Environment FREE CHAPTER 2. Learning Docker Commands 3. Creating Docker Images 4. Docker Volumes 5. Docker Swarm 6. Docker Networking 7. Docker Stacks 8. Docker and Jenkins 9. Other Books You May Enjoy

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

You have been reading a chapter from
Docker Quick Start Guide
Published in: Nov 2018
Publisher: Packt
ISBN-13: 9781789347326
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime