28,14 €
Develop and build your Docker images and deploy your Docker containers securely.
Key Features
Book 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.
What you will learn
Who this book is 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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 272
Veröffentlichungsjahr: 2018
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Vijin BorichaAcquisition Editor: Noyonika DasContent Development Editor: Kirk DsouzaTechnical Editor: Niral AlmeidaCopy Editor: Safis EditingProject Coordinator: Hardik BhindeProofreader: Safis EditingIndexer: Tejal Daruwale SoniGraphics: Alishon Mendonsa Production Coordinator: Arvindkumar Gupta
First published: November 2018
Production reference: 1281118
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78934-732-6
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
By eliminating variability in shipping and logistics, containers revolutionized the world back in 1956. This paradigm shift alone increased trade between nations, grew markets to a global scale, and decreased loading costs by approximately 97%. Today, Docker containers are having a similar revolutionary impact on the IT industry that no one can afford to fall behind.
I have been in the industry for more than 14 years, leading next-generation technology implementation efforts in world-class enterprise companies where technology is in the heart of the business, contributing toward their revenue. Throughout my professional journey, I've had a chance to be a part of many technology shifts, including virtualization, public cloud, software-defined data centers, infrastructure as a code, and containers. Lately, I've been focusing on delivering a universal container image and artifact management platform for one of the top global fintech companies, Intuit.
I met the author of this book, Earl Waud, during a technology presentation back in 2010. First impressions matter most, and I accidentally spilled a cup of coffee on his notebook—which turned out to be the beginning of a lifelong friendship.
After knowing Earl for more than eight years, I would describe him as a very professional, innovative, methodical, self-driven, and genuine person, allowing him to achieve any goal that he desires. There are countless examples of him coming up with an innovative idea, designing it on paper, engineering it in the lab, and implementing it in production to help and serve mission-critical, multibillion-dollar, revenue-generating products.
Historically, the infrastructure side and the software side of the IT industry have been disconnected for a long time. There are many interdependencies between both sides, yet most of the technologies and capabilities were siloed and handled differently. Docker container technology is bridging this gap by introducing a standardized way of building, packaging, and delivering software. Although there are several container technologies available, many professionals have chosen to use Docker because it is one of the most stable and effective platforms.
In Docker Quick Start Guide, by Earl Waud, Earl clearly depicts how you can build, package, and deploy your software as a container. He provides insight into many container related technologies with hands-on examples, allowing you to pick the right containerization approach for your software. With the skill set that you will gain from this book, you will be able to transform your traditional software to containerized software very rapidly, effectively, and successfully for all your business needs.
If decreasing cost, time to market, and variability is important for your business, and software containerization is in your roadmap to achieve these goals, Docker Quick Start Guide is one of the most important references that you can have in your library.
I would like to conclude by, one more time, saying thank you to the author of this book, Earl Waud, for leading the way by setting an example for the rest of the world, both at a professional level and a personal level. "We always win" my friend.
– Mert Cubukcuoglu
Senior Manager, Intuit Inc.
Earl Waud is a virtualization development professional with more than 20 year's experience developing customer-facing, enterprise-grade software for VM, and works with container provisioning, management, and automation.
Earl has a proven track record of delivering on-time solutions that significantly impact business results; solutions that align engineering strategies with organizational vision.
Recently, Earl has been creating AWS-based container solutions for enterprises using Docker, Kubernetes, Artifactory, Xray, and Twistlock.
Currently, Earl is a senior software engineer with Intuit Inc. Other books by Earl include Mastering Chef Provisioning and Chef: Powerful Infrastructure Automation. Earl can be found online at SanDiegoEarl (dot) com.
Paul Adamson has worked as an Ops engineer, a developer, a DevOps engineer, and everything in between. When not reviewing this book, Paul keeps busy helping companies embrace the AWS infrastructure. His language of choice is PHP, for all the good reasons and even some of the bad, but mainly out of habit. While reviewing this book, Paul has been working for Healthy Performance Ltd, helping to apply cutting-edge technology to a cutting-edge approach to well being.
Mert Cubukcuoglu is a senior information technology leader with more than 12 years experience in implementing and leading enterprise-level, next-generation platform solutions within large data centers and the public cloud. His expertise in delivering mission-critical innovative technology solutions that are aligned with overall strategy and business goals provides him with a competitive advantage in any industry. Currently, Mert is leading compute engineering and automation teams at Intuit, a leader in the small business and personal finance software industry.
Rod Foster is an innovative, pro-active, and performance-driven Solutions Architect with more than 14 years of experience in the Information Technology and Services industry, including 10 years of direct focus on Virtualization. Rod is currently one of the leaders on Intuit's exceptional Cloud and Hypervisor Team, he is directly responsible for the engineering and implementation of Intuit's Cloud (AWS) and VMware vSphere architecture that support its TurboTax, QuickBooks, and Mint offerings. When Rod isn't busy innovating, mentoring and providing quality assurance oversight to Intuit's vast portfolio of services, he enjoys fitness, music, and traveling! Special thanks to Earl Waud for allowing me to take part in the creation of this book!
Jitesh Marathe is an IT professional with a Bachelor degree in Computer Application; he has spent most of his career being a System Administrator in various IT companies and specialized in the System and DevOps Role. Jitesh enjoys traveling to new places with his family. Jitesh has reviewed a few other books including Linux Utilities Cookbook, and Mastering Linux Network Administration.
Vishnu Gopal is an engineer with strong product and user-experience skills, with experience in product development, web development, and engineering management. He was part of the initial team that built SlideShare Inc., which then went on to be acquired by LinkedIn. He has been working in the web and mobile development field for over 10 years. He is currently CTO of SV.CO, a product accelerator for students based in India. He lives in Kochi, India.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Docker Quick Start Guide
Dedication
About Packt
Why subscribe?
Packt.com
Foreword
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Code in action
Conventions used
Get in touch
Reviews
Setting up a Docker Development Environment
Technical requirements
Setting up your Docker development environment
Installing Docker on a Linux workstation
Installing Docker on a CentOS workstation
Installing Docker CE via the Docker Repository
Installing Docker CE manually using a downloaded RPM
Installing Docker CE by running convenience scripts
Post-install steps you might want to consider
Installing Docker on an Ubuntu workstation
Installing Docker CE via the Docker Repository
Installing Docker CE manually using a DEB package
Installing Docker CE by running convenience scripts
Post-install steps you might want to consider
Installing Docker on a Windows workstation
Post-install steps you might want to consider
Installing Kitematic
Setting up DockerCompletion for PowerShell 
Installing Docker on an OS X workstation
Post-install steps you might want to consider
Installing Kitematic
Installing Docker command-line completion
References
What differences to watch out for between OSes
Summary
References
Learning Docker Commands
Technical requirements
Information about command syntax
The version command
The Docker run command
The list container command
The remove container command
The stop container command
The container logs command
The container top command
The container inspect command
The container stats command
The container attach command
The container exec command
The container commit command
Back to the Docker run command
Summary
References
Creating Docker Images
Technical requirements
What is a Dockerfile?
The FROM instruction
The LABEL instruction
The COPY instruction
The ADD instruction
The difference between COPY and ADD
The ENV instruction
The ARG instruction
The difference between ENV and ARG
The USER instruction
The WORKDIR instruction
The VOLUME instruction
The EXPOSE instruction
The RUN instruction
The CMD instruction
The ENTRYPOINT instruction
The difference between CMD and ENTRYPOINT
The HEALTHCHECK instruction
The ONBUILD instruction
The STOPSIGNAL instruction
The SHELL instruction
The Docker image build command
Parser Directives
The build context
The .dockerignore file
Summary
References
Docker Volumes
Technical requirements
What is a Docker volume?
References
Creating Docker volumes
References
Removing volumes
References
Sharing data between containers with data volume containers
References
Summary
Docker Swarm
Technical requirements
What is Docker swarm?
References
How to set up a Docker swarm cluster
docker swarm init
docker swarm join-token
docker swarm join
docker swarm ca
docker swarm unlock
docker swarm unlock-key
docker swarm update
docker swarm leave
References
Managers and workers
References
Swarm services
References
Accessing container applications in a swarm
References
Summary
Docker Networking
Technical requirements
What is a Docker network?
References
Built-in (local) Docker networks
References
Third-party (remote) network drivers
References
Creating Docker networks
References
Free networking features
References
Which Docker network driver should I use?
Summary
Docker Stacks
Technical requirements
Understanding the use of Docker stacks
References
How to create and use a compose YAML files for Stacks
The rest of the stack commands
Best practices for scaling a stack application
References
Summary
Docker and Jenkins
Technical requirements
Using Jenkins to build Docker images
References
Setting up a Dockerized Jenkins server
References
Building Docker images inside of a Dockerized Jenkins server
References
Using Docker containers for your Jenkins build nodes
Building the Docker image
Pushing the new image to a Docker registry
Turning off the default Jenkins build agents
Installing the Docker plugin for Jenkins
Creating a new Cloud to enable our Dockerized build agents
Testing our new build agents
Building, testing, and pushing Docker images inside Dockerized build nodes
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
Usually, the first question I get when I mention Docker or this book is What is Docker? So, we might as well answer that question right now and get it out of the way...
Within the circle of friends I hang out with, I would answer that question by saying Docker is a software solution used to build, ship, and run containers anywhere. But if you are not a computer person, then that answer would mean next to nothing to you. So, let's try again, and answer the question What is Docker? in a way that is worthy of a Quick Start Guide.
Docker is a tool that allows software developers to easily create applications, and wrap those applications in a special package called a container. Used correctly, an application packaged as a container can be run very efficiently, and very securely. And since the container has everything the application needs to run, it also allows the developer to share their application nearly anywhere, without ever having to re-create or re-package it.
This means that as a result of using Docker, a developer can create, run, and test their application container on their own laptop and then share the exact same container with their peers so that it can be run and tested by them as well. Then, they can share the same container with the quality assurance team for further validation of quality, and ultimately, the exact same container can be run and used by customers in a production setting.
Using Docker, software developers can create better, more secure software that can be tested and deployed faster than ever before.
Within the pages of this book, you are going to find all of the information that you need to understand what Docker is and what benefits Docker provides. Using detailed, yet easy-to-follow, descriptions and examples, this Quick Start Guide will teach you how to set up your own Docker development environment, and how to create enterprise-grade Docker images that utilize all of the important features that Docker provides. This Quick Start Guide will teach you how to use Docker networking and Docker's storage features. You will also learn how to create and deploy multi-container applications, and how to set up Docker clustering using Docker Swarm. By the time you finish the Quick Start Guide, you will be building and sharing your own Docker images, and running your most important applications in Docker containers. This Quick Start Guide will thoroughly prepare you to use Docker for all of your future projects. If you are ready to get started, turn the page...
This Quick Start Guide is written for anyone who wants to know what Docker is and understand why so many people are so excited about using it. It is intended for developers who want to get started using Docker right away and don't have time to wade through a full Mastering Docker book, or attend a week-long training course. This guide is for anyone who needs to make a quick decision about using Docker for their next project and get started right away.
Chapter 1, Setting up a Docker Development Environment, covers getting everything set up for Docker development on our workstation. We learn how to set up a Docker development environment on Linux, Windows, and OS X workstations. We will then 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.
Chapter 2, Learning Docker Commands, introduces a number of essential Docker commands. While we focus on one of the most important commands, the container run command, we will also cover many other commands that you will be using on a daily basis. These commands include the list container command, the stop container command, and the remove container command. Along the way, we will also discover other container commands, such as logs, inspect, stats, attach, exec, and commit. I think you will find this chapter to be an excellent foundation in terms of your Docker education.
Chapter 3, Creating Docker Images, covers how to create enterprise-grade Docker images. We will start off by learning about the main building block of Docker images; specifically, the Dockerfile. We will then explore all the instructions available to use in a Dockerfile. There are some instructions, that, on the face of it, will seem very similar. We will uncover the differences between the COPY and ADD instructions, the ENV and ARG instructions, and, most importantly, between the CMD and ENTRYPOINT instructions. Then, we will find out what the build context is and why it is important. Finally, we will cover the actual image build command.
Chapter 4, Docker Volumes, uncovers the secrets of Docker volumes. We will learn how to use folders on your workstation inside your Docker containers, as well as how to create and use persistent volumes, allowing multiple containers to share data. We will learn how to clean up after unused volumes. And finally, to round it out, we will learn how to create data volume containers to become the source of volumes for other containers.
Chapter 5, Docker Swarm, covers what Docker swarm is, and how to set up a Docker swarm cluster. We will find out more about swarm managers and swarm workers. We will discover Swarm Services. We will find out how easy it is to access a container application running on any node in the swarm cluster.
Chapter 6, Docker Networking, introduces Docker networking. We will dive deep into Docker networking, learning how containers can be isolated, how they can communicate with each other, and how they can communicate with the outside world. We will explore the local network drivers Docker provides in the out-of-the-box installation. We will then examine the use of remote network drivers with an example deployment of the Weave driver. After that, we will learn how to create Docker networks and round out the discussion with a look at the free services that we get with our Docker networks.
Chapter 7, Docker Stacks, brings together everything we will have learned in the first six chapters in order to be able to define, deploy, and manage multi-container applications. We will achieve this via the use of Docker stacks. We are going to learn how to use Docker stacks and the YAML files required to define multi-container applications. And, we will leverage what we learned about Docker services, Docker volumes, Docker swarm, and Docker networking to create full-featured, multi-service Docker-based applications.
Chapter 8, Docker and Jenkins, covers how to leverage Jenkins to build our Docker images and deploy our Docker containers. We will learn how to deploy our Jenkins server as a Docker container. We will follow that by learning how to build Docker images within the Dockerized Jenkins server. This is what is often referred to as Docker in Docker. Finally, we will see how to utilize Docker containers as the Jenkins build agents, allowing every build to be run in a pristine, ephemeral Docker container. Of course, we will show how to build Docker images, test applications, and push tested images to a Docker registry, all within our Dockerized Jenkins build agents. This will provide you with all the tools you will need to set up your CI/CD systems.
You should have a developer workstation that you can install Docker on and use to test out the examples included in this book. You will learn the most by actually trying each of the examples yourself instead of just reading over them. In addition, you should have access to at least one other, but preferably two or three other, servers to configure as a Docker swarm. These servers can be EC2 instances in AWS; or VMs on VMware Workstation or Fusion; or, worst case scenario, VMs in VirtualBox. All of the software used throughout this book is free or open source, so you should be able to try out everything you are learning here. Most of the examples will work equally well regardless of the OS you are using, and I have tried to call out the differences where appropriate. You should have an account created on https://hub.docker.com, and an account on https://github.com. All of the code samples have been tested by me, as well as by several reviewers, so if you don't get them to work, double-check the code and try again, or download the code from Packt and cut and paste it into your system, and then try again. You'll get the hang of it.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Docker-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Visit the following link to check out videos of the code being run: http://bit.ly/2Q1DbPq
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In the networks key section, we are instructing Docker to create two networks, one named frontend and one named backend."
Any command-line input or output is written as follows:
# Enable autolock on your swarm cluster
docker swarm update --autolock=true
# Adjust certificate expiry to 30 days
docker swarm update --cert-expiry 720h
Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Once the configuration has been saved, let's test the job by clicking on the Build Now link."
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
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
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
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, i
