Mastering Docker
eBook - ePub

Mastering Docker

Unlock new opportunities using Docker's most advanced features, 3rd Edition

Russ McKendrick, Scott Gallagher

Share book
  1. 426 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Docker

Unlock new opportunities using Docker's most advanced features, 3rd Edition

Russ McKendrick, Scott Gallagher

Book details
Book preview
Table of contents
Citations

About This Book

Master Docker and leverage its power in your day-to-day workflow

Key Features

  • 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

Book 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.

What you will learn

  • Become fluent 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 workflow
  • 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

Who this book is 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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering Docker an online PDF/ePUB?
Yes, you can access Mastering Docker by Russ McKendrick, Scott Gallagher in PDF and/or ePUB format, as well as other popular books in Computer Science & Virtualisation. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789618686
Edition
3

Managing Containers

So far, we have been concentrating on how to build, store, and distribute our Docker images. Now we are going to look at how we can launch containers, and also how we can use the Docker command-line client to manage and interact with them.
We will be revisiting the commands we used in the first chapter by going into a lot more detail, before delving deeper into the commands that are available. Once we are familiar with the container commands, we will look at Docker networks and Docker volumes.
We will cover the following topics:
  • Docker container commands:
    • The basics
    • Interacting with your containers
    • Logs and process information
    • Resource limits
    • Container states and miscellaneous commands
    • Removing containers
  • Docker networking and volumes

Technical requirements

In this chapter, we will continue to use our local Docker installation. As before, the screenshots in this chapter will be from my preferred operating system, macOS, but 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 be applicable only to macOS and Linux-based operating systems.
Check out the following video to see the Code in Action:
http://bit.ly/2yupP3n

Docker container commands

Before we dive into the more complex Docker commands, let's review and go into a little more detail on the commands we have used in previous chapters.

The basics

In Chapter 1, Docker Overview, we launched the most basic container of all, the hello-world container, using the following command:
$ docker container run hello-world
As you may recall, this command pulls a 1.84 KB image from the Docker Hub. You can find the Docker Store page for the image at https://store.docker.com/images/hello-world/, and as per the following Dockerfile, it runs an executable called hello:
FROM scratch
COPY hello /
CMD ["/hello"]
The hello executable prints the Hello from Docker! text to the Terminal, and then the process exits. As you can see from the full message text in the following Terminal output, the hello binary also lets you know exactly what steps have just occurred:
As the process exits, our container also stops; this can be seen by running the following command:
$ docker container ls -a
The output of the command is given here:
You may notice in the Terminal output that I first ran docker container ls with and without the -a flag—this is shorthand for --all, as running it without the flag does not show any exited containers.
We didn't have to name our container as it wasn't around long enough for us to care what it was called. Docker automatically assigns names for containers, though, and in my case, you can see that it was called pensive_hermann.
You will notice, throughout your use of Docker, that it comes up with some really interesting names for your containers if you choose to let it generate them for you. Although this is slightly off-topic, the code to generate the names can be found in names-generator.go. Right at the end of the source code, it has the following if statement:
if name == "boring_wozniak" /* Steve Wozniak is not boring */ {
goto begin
}
This means there will never be a container called boring_wozniak (and quite rightly, too).
Steve Wozniak is an inventor, electronics engineer, programmer, and entrepreneur who co-founded Apple Inc. with Steve Jobs. He is known as a pioneer of the personal computer revolution of the 70s and 80s, and is definitely not boring!
We can remove the container with a status of exited by running the following command, making sure that you replace the name of the container with your own container name:
$ docker container rm pensive_hermann
Also, at the end of Chapter 1, Docker Overview, we launched a container using the official nginx image, using the following command:
$ docker container run -d --name nginx-test -p 8080:80 nginx
As you may remember, this downloads the image and runs it, mapping port 8080 on our host machine to port 80 on the container, and calls it nginx-test:
As you can see, running docker image ls shows us that we now have two images downloaded and also running. The following command shows us that we have a running container:
$ docker container ls
The following Terminal output shows that mine had been up for 5 minutes when I ran the command:
As you can see from our docker container run command, we introduced three flags. One of them was -d, which is shorthand for --detach. If we hadn't added this flag, then our container would have executed in the foreground, which means that our Terminal would have been frozen until we passed the process an escape command by pressing Ctrl + C.
We can see this in action by running the following command to launch a second nginx container to run alongside the container we have already launched:
$ docker container run --name nginx-foreground -p 9090:80 nginx
Once launched, open a browser and go to http://localhost:9090/. As you load the page, you will notice that your page visit is printed to the screen; hit...

Table of contents