Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Continuous Delivery with Docker and Jenkins
Continuous Delivery with Docker and Jenkins

Continuous Delivery with Docker and Jenkins: Delivering software at scale

eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Continuous Delivery with Docker and Jenkins

Introducing Docker

We will discuss how the modern Continuous Delivery process should look by introducing Docker, the technology that changed the IT industry and the way the servers are used.

This chapter covers the following points:

  • Introducing the idea of virtualization and containerization
  • Installing Docker for different local and server environments
  • Explaining the architecture of the Docker toolkit
  • Building Docker images with Dockerfile and by committing changes
  • Running applications as Docker containers
  • Configuring Docker networks and port forwarding
  • Introducing Docker volumes as a shared storage

What is Docker?

Docker is an open source project designed to help with application deployment using software containers. This quote is from the official Docker page:

"Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries - anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment."

Docker, therefore, in a similar way as virtualization, allows packaging an application into an image that can be run everywhere.

Containerization versus virtualization

Without Docker, isolation and other benefits can be achieved with the use of hardware virtualization...

Docker installation

Docker's installation process is quick and simple. Currently, it's supported on most Linux operating systems and a wide range of them have dedicated binaries provided. Mac and Windows are also well supported with native applications. However, it's important to understand that Docker is internally based on the Linux kernel and its specifics, and this is why, in the case of Mac and Windows, it uses virtual machines (xhyve for Mac and Hyper-V for Windows) to run the Docker Engine environment.

Prerequisites for Docker

Docker requirements are specific for each operating system.

Mac:

  • 2010 or newer model, with Intel’s hardware support for memory management unit (MMU) virtualization
  • macOS...

Running Docker hello world>

The Docker environment is set up and ready, so we can start the first example.

Enter the following command in your console:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

Congratulations, you've just run your first Docker container. I hope you already feel how simple Docker is. Let's examine step-by-step what happened under the hood:

  1. You ran the Docker client with the run command.
  2. The Docker client contacted the Docker daemon asking to create a container from the image called hello-world.
  3. The Docker daemon checked...

Docker applications

A lot of applications are provided in the form of Docker images that can be downloaded from the internet. If we knew the image name, then it would be enough to run it in the same way we did with the hello world example. How can we find the desired application image on the Docker Hub?

Let's take MongoDB as an example. If we like to find it on the Docker Hub, we have two options:

In the second case, we can perform the following operation:

$ docker search mongo
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mongo MongoDB document databases provide high av... 2821 [OK]
mongo-express Web-based MongoDB admin interface, written... 106 [OK]
mvertes/alpine-mongo light MongoDB container 39 [OK]
mongoclient/mongoclient Official docker image for Mongoclient, fea... 19...

Building images

Docker can be treated as a useful tool to run applications; however, the real power lies in building own Docker images that wrap the programs together with the environment. In this section, we will see how to do this using two different methods, the Docker commit command and the Dockerfile automated build.

Docker commit

Let's start with an example and prepare an image with the Git and JDK toolkits. We will use Ubuntu 16.04 as a base image. There is no need to create it; most base images are available in the Docker Hub registry:

  1. Run a container from the ubuntu:16.04 and connect it to its command line:
        $ docker run -i -t ubuntu:16.04 /bin/bash

We've pulled the ubuntu:16.04 image and run it...

Docker container states

Every application we've run so far was supposed to do some work and stop. For example, we've printed Hello from Docker! and exited. There are, however, applications that should run continuously such as services. To run a container in the background, we can use the -d (--detach) option. Let's try it with the ubuntu image:

$ docker run -d -t ubuntu:16.04

This command started the Ubuntu container but did not attach the console to it. We can see that it's running using the following command:

$ docker ps
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
95f29bfbaadc ubuntu:16.04 "/bin/bash" Up 5 seconds kickass_stonebraker

This command prints all containers that are in the running state. What about our old, already-exited containers? We can find them by printing all containers:

$ docker ps -a
CONTAINER ID IMAGE COMMAND...

Docker networking

Most applications these days do not run in isolation but need to communicate with other systems over the network. If we want to run a website, web service, database, or a cache server inside a Docker container, then we need to understand at least the basics of Docker networking.

Running services

Let's start with a simple example, and run a Tomcat server directly from Docker Hub:

$ docker run -d tomcat

Tomcat is a web application server whose user interface can be accessed by the port 8080. Therefore, if we installed Tomcat on our machine, we could browse it at http://localhost:8080.

In our case, however, Tomcat is running inside the Docker container. We started it the same way we did with the first Hello...

Using Docker volumes

Imagine that you would like to run the database as a container. You can start such a container and enter the data. Where is it stored? What happens when you stop the container or remove it? You can start the new one, but the database will be empty again. Unless it's your testing environment, you don't expect such a scenario.

Docker volume is the Docker host's directory mounted inside the container. It allows the container to write to the host's filesystem as it was writing to its own. The mechanism is presented in the following diagram:

Docker volume enables the persistence and sharing of the container's data. Volumes also clearly separate the processing from the data.

Let's start with an example and specify the volume with the -v <host_path>:<container_path> option and connect to the container:

$ docker run -i ...

Using names in Docker

So far, when we operated on the containers, we always used autogenerated names. This approach has some advantages, such as the names being unique (no naming conflicts) and automatic (no need to do anything). In many cases, however, it's better to give a real user-friendly name for the container or the image.

Naming containers

There are two good reasons to name the container: convenience and the possibility of automation:

  • Convenience, because it's simpler to make any operations on the container addressing it by name than checking the hashes or the autogenerated name
  • Automation, because sometimes we would like to depend on the specific naming of the container

For example, we would like to have...

Docker cleanup

Throughout this chapter, we have created a number of containers and images. This is, however, only a small part of what you will see in real-life scenarios. Even when the containers are not running at the moment, they need to be stored on the Docker host. This can quickly result in exceeding the storage space and stopping the machine. How can we approach this concern?

Cleaning up containers

First, let's look at the containers that are stored on our machine. To print all the containers (no matter of their state), we can use the docker ps -a command:

$ docker ps -a
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
95c2d6c4424e tomcat "catalina.sh run" Up 5 minutes 8080/tcp tomcat
a9e0df194f1f...

Docker commands overview

All Docker commands can be found by executing the following help command:

$ docker help

To see all the options of any particular Docker command, we can use docker help <command>, for example:

$ docker help run

There is also a very good explanation of all Docker commands on the official Docker page https://docs.docker.com/engine/reference/commandline/docker/. It's really worth reading or at least skimming through.

In this chapter, we've covered the most useful commands and their options. As a quick reminder, let's walk through them:

Command Explanation
docker build

Build an image from a Dockerfile

docker commit

Create an image from the container

docker diff

Show changes in the container

docker images

List images

docker info

Display Docker information

docker inspect

Show the configuration of the Docker image...

Exercises

We've covered a lot of material in this chapter. To make well-remembered, we recommend two exercises.

  1. Run CouchDB as a Docker container and publish its port:
You can use the docker search command to find the CouchDB image.
    • Run the container
    • Publish the CouchDB port
    • Open the browser and check that CouchDB is available
  1. Create a Docker image with the REST service replying Hello World! to localhost:8080/hello. Use any language and framework you prefer:
The easiest way to create a REST service is to use Python with the Flask framework, http://flask.pocoo.org/. Note that a lot of web frameworks start the application on the localhost interface only by default. In order to publish a port, it's necessary to start it on all interfaces (app.run(host='0.0.0.0') in the case of a Flask framework).
    • Create a web service application
    • Create a Dockerfile...

Summary

In this chapter, we have covered the Docker basics that are enough to build images and run applications as containers. The key takeaway, from the chapter are the following points:

  • The containerization technology addresses the issues of isolation and environment dependencies using the Linux kernel features. This is based on the process separation mechanism, therefore no real performance drop is observed.
  • Docker can be installed on most of the systems but is supported natively only on Linux.
  • Docker allows running applications from the images available on the internet and to build own images.
  • An image is an application packed together with all dependencies.
  • Docker provides two methods for building the images: Dockerfile or committing the container. In most cases, the first option is used.
  • Docker containers can communicate over the network by publishing the ports they expose...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build reliable and secure applications using Docker containers.
  • Create a complete Continuous Delivery pipeline using Docker, Jenkins, and Ansible.
  • Deliver your applications directly on the Docker Swarm cluster.
  • Create more complex solutions using multi-containers and database migrations.

Description

The combination of Docker and Jenkins improves your Continuous Delivery pipeline using fewer resources. It also helps you scale up your builds, automate tasks and speed up Jenkins performance with the benefits of Docker containerization. This book will explain the advantages of combining Jenkins and Docker to improve the continuous integration and delivery process of app development. It will start with setting up a Docker server and configuring Jenkins on it. It will then provide steps to build applications on Docker files and integrate them with Jenkins using continuous delivery processes such as continuous integration, automated acceptance testing, and configuration management. Moving on you will learn how to ensure quick application deployment with Docker containers along with scaling Jenkins using Docker Swarm. Next, you will get to know how to deploy applications using Docker images and testing them with Jenkins. By the end of the book, you will be enhancing the DevOps workflow by integrating the functionalities of Docker and Jenkins.

Who is this book for?

This book is indented to provide a full overview of deep learning. From the beginner in deep learning and artificial intelligence to the data scientist who wants to become familiar with Theano and its supporting libraries, or have an extended understanding of deep neural nets. Some basic skills in Python programming and computer science will help, as well as skills in elementary algebra and calculus.

What you will learn

  • Get to grips with docker fundamentals and how to dockerize an application for the Continuous Delivery process
  • Configure Jenkins and scale it using Docker-based agents
  • Understand the principles and the technical aspects of a successful Continuous Delivery pipeline
  • Create a complete Continuous Delivery process using modern tools: Docker, Jenkins, and Ansible
  • Write acceptance tests using Cucumber and run them in the Docker ecosystem using Jenkins
  • Create multi-container applications using Docker Compose
  • Managing database changes inside the Continuous Delivery process and understand effective frameworks such as Cucumber and Flyweight
  • Build clustering applications with Jenkins using Docker Swarm
  • Publish a built Docker image to a Docker Registry and deploy cycles of Jenkins pipelines using community best practices
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 24, 2017
Length: 332 pages
Edition : 1st
Language : English
ISBN-13 : 9781787125230
Vendor :
Docker
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : Aug 24, 2017
Length: 332 pages
Edition : 1st
Language : English
ISBN-13 : 9781787125230
Vendor :
Docker
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 106.97
Learning Continuous Integration with Jenkins
€36.99
Deployment with Docker
€32.99
Continuous Delivery with Docker and Jenkins
€36.99
Total 106.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Introducing Continuous Delivery Chevron down icon Chevron up icon
Introducing Docker Chevron down icon Chevron up icon
Configuring Jenkins Chevron down icon Chevron up icon
Continuous Integration Pipeline Chevron down icon Chevron up icon
Automated Acceptance Testing Chevron down icon Chevron up icon
Configuration Management with Ansible Chevron down icon Chevron up icon
Continuous Delivery Pipeline Chevron down icon Chevron up icon
Clustering with Docker Swarm Chevron down icon Chevron up icon
Advanced Continuous Delivery Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(3 Ratings)
5 star 33.3%
4 star 33.3%
3 star 33.3%
2 star 0%
1 star 0%
Adam Nov 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the best book available on the topic, period. I've also read a couple of other books on the topic, but they are outdated.This is the most up to date manual at the moment on how to implement Continuous Delivery with Docker and Jenkins.It covers Jenkins 2 and uses the latest features of Docker (swarm, stack).A big thank you to the author who put together this great book.Thank you.
Amazon Verified review Amazon
Joginder Raperia Jan 23, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Explains Jenkins, Ansible and Docker in a very easy way. Gives a very good starting point for anyone new in the area of Containers, Configuration Management and Continuous Delivery.
Amazon Verified review Amazon
lowtek Mar 26, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Some good tips but didn't really learn anything new. If you already understand CI and CD and use Jenkins/Docker often this won't be anything new for you either. Some good best practices listed but again nothing groundbreaking
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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela