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

Mastering Docker: Unlock new opportunities using Docker's most advanced features , Third Edition

Arrow left icon
Profile Icon Russ McKendrick Profile Icon Scott Gallagher
Arrow right icon
R$80 R$245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Oct 2018 426 pages 3rd Edition
eBook
R$80 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m
Arrow left icon
Profile Icon Russ McKendrick Profile Icon Scott Gallagher
Arrow right icon
R$80 R$245.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Oct 2018 426 pages 3rd Edition
eBook
R$80 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m
eBook
R$80 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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
Table of content icon View table of contents Preview book icon Preview Book

Mastering Docker

Building Container Images

In this chapter, we are going to get you started building container images. We will look at several different ways with which you can define and build your images using the tools built into Docker. We will cover the following topics:

  • Introducing the Dockerfile
  • Building container images using a Dockerfile
  • Building container images using an existing container
  • Building container images from scratch
  • Building container images using environmental variables
  • Building container images using multi-stage builds

Technical requirements

In the previous chapter, we installed Docker on the following target operating systems:

  • macOS High Sierra and above
  • Windows 10 Professional
  • Ubuntu 18.04

In this chapter, we will be using our Docker installation to build images. While the screenshots in this chapter will be from my preferred operating system, which is macOS, the Docker commands we will be running will work on all three of the operating systems on which we have installed Docker so far. However, some of the supporting commands, which will be few and far between, may only be applicable to macOS and Linux-based operating systems.

A full copy of the code used in this chapter can be found at: https://github.com/PacktPublishing/Mastering-Docker-Third-Edition/tree/master/chapter02

Check out the following video to see the Code in Action:

http://bit.ly/2D0JA6v

...

Introducing the Dockerfile

In this section, we will cover Dockerfiles in depth, along with the best practices to use. So what is a Dockerfile?

A Dockerfile is simply a plain text file that contains a set of user-defined instructions. When the Dockerfile is called by the docker image build command, which we will look at next, it is used to assemble a container image. A Dockerfile looks like the following:

FROM alpine:latest
LABEL maintainer="Russ McKendrick <russ@mckendrick.io>"
LABEL description="This example Dockerfile installs NGINX."
RUN apk add --update nginx && \
rm -rf /var/cache/apk/* && \
mkdir -p /tmp/nginx/

COPY files/nginx.conf /etc/nginx/nginx.conf
COPY files/default.conf /etc/nginx/conf.d/default.conf
ADD files/html.tar.gz /usr/share/nginx/

EXPOSE 80/tcp

ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;&quot...

Building container images

In this section, we will cover the docker image build command. This is where the rubber meets the road, as they say. It's time for us to build the base upon which we will start building our future images. We will be looking at different ways to accomplish this goal. Consider this as a template that you may have created earlier with virtual machines. This will help save time by completing the hard work; you will just have to create the application that needs to be added to the new images.

There are a lot of switches that you could use while using the docker build command. So, let's use the always handy --help switch on the docker image build command to view all that we can do:

$ docker image build --help

There are then a lot of different flags listed that you can pass when building your image. Now, it may seem like a lot to digest, but out of...

Summary

In this chapter, we looked at an in-depth view of Dockerfiles, the best practices for writing them, the docker image build command, and the various ways we can build containers. We also learned about the environmental variables that you can use to pass from your Dockerfile to the various items inside your containers.

In the next chapter, now that we know how to build images using Dockerfiles, we will be taking a look at the Docker Hub and all of the advantages that using a registry service brings. We will also look at the Docker registry, which is open source, so you can roll your own place to store images without the fees of Docker Enterprise, as well as third-party registry services.

Questions

  1. True or false: The LABEL instruction tags your image once it has been built?
  2. What's the difference between the ENTRYPOINT and CMD instructions?
  3. True or false: when using the ADD instruction, you can’t download and automatically uncompress an externally hosted archive?
  4. What is a valid use for using an existing container as the base of your image?
  5. What does the EXPOSE instruction expose?

Further reading

You can find the guidelines for the official Docker container images at:

Some of the tools to help you create containers from existing installations are the following:

Finally, the full GitHub repository for the Go HTTP Hello World application can be found at:

Left arrow icon Right arrow icon

Key benefits

  • Explore tools such as Docker Engine, Machine, Compose, and Swarm
  • Discover how Docker can be integrated into your daily workflows
  • Learn to leverage Docker Swarm and Kubernetes

Description

Docker has been a game-changer when it comes to how modern applications are deployed and created. It has now grown into a key driver of innovation beyond system administration, with an impact on the world of web development. But how can you make sure you're keeping up with the innovations it's driving, or be sure you're using it to its full potential? Mastering Docker shows you how; this book not only demonstrates how to use Docker more effectively, but also helps you rethink and reimagine what's possible with it. You will cover concepts such as building, managing, and storing images, along with best practices to make you confident, before delving more into Docker security. You'll find everything related to extending and integrating Docker in new and innovative ways. Docker Compose, Docker Swarm, and Kubernetes will help you take control of your containers in an efficient manner. By the end of the book, you will have a broad, yet detailed, sense of what's possible with Docker, and how seamlessly it fits in with a range of other platforms and tools.

Who is this book for?

If you are an I.T professional and recognize Docker's importance for innovation in everything from system administration to web development, but aren't sure how to use it to its full potential, Mastering Docker is for you.

What you will learn

  • Become ?uent with the basic components and concepts of Docker
  • Learn the best ways to build, store, and distribute containers
  • Understand how Docker can fit into your development work?ow
  • Secure your containers and files with Docker s security features
  • Solve architectural problems using the first and third clustering tool
  • Leverage Linux containers and create highly scalable applications

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 25, 2018
Length: 426 pages
Edition : 3rd
Language : English
ISBN-13 : 9781789618686
Vendor :
Docker
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Product Details

Publication date : Oct 25, 2018
Length: 426 pages
Edition : 3rd
Language : English
ISBN-13 : 9781789618686
Vendor :
Docker
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 852.97
Mastering Docker
R$306.99
Getting Started with Kubernetes
R$272.99
Docker Cookbook
R$272.99
Total R$ 852.97 Stars icon

Table of Contents

16 Chapters
Docker Overview Chevron down icon Chevron up icon
Building Container Images Chevron down icon Chevron up icon
Storing and Distributing Images Chevron down icon Chevron up icon
Managing Containers Chevron down icon Chevron up icon
Docker Compose Chevron down icon Chevron up icon
Windows Containers Chevron down icon Chevron up icon
Docker Machine Chevron down icon Chevron up icon
Docker Swarm Chevron down icon Chevron up icon
Docker and Kubernetes Chevron down icon Chevron up icon
Running Docker in Public Clouds Chevron down icon Chevron up icon
Portainer - A GUI for Docker Chevron down icon Chevron up icon
Docker Security Chevron down icon Chevron up icon
Docker Workflows Chevron down icon Chevron up icon
Next Steps with Docker Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Amazon Kunde Jul 27, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
N/A
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.