Table of Contents
- 0: About the book
- 4: The big picture
0: About the book
This is a book about Docker, hand-crafted for system administrators. No prior knowledge required!
But what about developers and DevOps?
If you’re a developer with no interest in operations then this book is not for you. If you’re into DevOps then you’ll get a lot from the book.
To keep things short… the book is not about showing you how to develop microservice apps with Docker. The book is about how Docker works. You’ll learn the how and the why - the commands and the theory. I really want to set you on your way to being as good at Docker as you already are at Linux, Windows or VMware.
Why should I read this book or care about Docker?
Docker is coming and there’s no hiding from it. Developers are all over it. In IT Ops, we need to get ready to support Dockerized apps in our business critical production environments.
Isn’t Docker just for developers?
If you think the answer to that is Yes, then you need a good slap!
All of those Dockerized apps that developers are creating need a solid Docker infrastructure to run on. And that’s where Ops comes into the picture… Ops will need to build and run high performance and highly available Docker infrastructures. If we’re not skilled-up on Docker, we’re going to struggle.
Why this Docker book and not one of the others?
At the time I decided to write the first edition of this book, so many of the Docker books already out there were terrible! Many of them were badly written, full of technical inaccuracies, or massively out of date. And sometimes they were all three! It’s honestly not my intention to offend people, but go and read some of the reviews on Amazon. Some of the Docker books out there are a shameful waste of trees and paper!
So I decided to write something that was well written, technically accurate, and kept up to date. I don’t want you to buy this book and put it on the shelf. I want you to love this book!
If you buy the book and think it’s bad, call me out on Twitter, give the book bad reviews, do whatever you feel necessary. And I’ll try and fix it. But I’m confident you won’t need to do any of that.
Should I buy the book if I’ve already watched your video courses?
If you like my video courses you’ll probably like the book. If you don’t like my video courses you probably won’t like the book.
How the book is organized
I’ve divided the book into two sections:
- The general info stuff
- The technical stuff
The general info stuff covers things like - Who is Docker, Inc. What is the Docker project. What is the OCI. Why do we even have containers… Not the coolest part of the book, but the kind of stuff that’s important if you want a good rounded knowledge of Docker and containers. It’s only a short section and you should probably read it.
The technical stuff is what the book is all about! This is where you’ll find everything you need to start working with Docker. It gets into the detail of images, containers and the increasingly important topic of orchestration. You’ll get the theory so that you know how it all fits together, and you’ll get commands and examples to show you how it all works in practice.
Every chapter in the technical stuff section is divided into three parts:
- The TLDR
- The deep dive
- The commands
The TLDR will give you two or three paragraphs that you could use to explain the topic at the coffee machine. They’re probably good as quick reminders if you get lost in the details.
TLDR or TL;DR, is a modern acronym meaning “too long; didn’t read”. It’s normally used to indicate something that was too long to bother reading. I’m using it here in the book to indicate a short section that you can read if you’re in a hurry and haven’t got time to read the longer deep dive that immediately follows it.
The deep dive is where we’ll explain how everything works and go through the examples.
The Commands lists out all of the relevant commands in an easy to read list with brief reminders of what each one does.
I think you’ll love that format.
Other stuff about the book
Here are just a few other things I want you to know about the book.
I’ve tried really hard to get the commands and outputs to fit on a single line without wrapping! So instead of getting this…
… you should get this.
For best results you might want to flip your reading device into landscape mode.
In doing this I’ve had to trim some of the output from some commands, but I don’t think you’re missing anything important. However, despite all of this, if you’re reading on a small enough device, you’re still going to get some wrapping :-(
But you didn’t include something I really hoped you would…
I know the book doesn’t cover everything about Docker. But it’s not supposed to! I’ve written the book to get you up to speed as quickly as possible while still spending the time to learn how it all fits together. If the book was 1,000 printed pages it would not help you get up to speed quickly!
However, I will add sections to the book if I think they’re important enough. Please use the book’s feedback pages and hit me up on Twitter with ideas of what you think should be included in the next version of the book.
Right, that’s enough waffling. Let’s crack on!
4: The big picture
In the next few chapters we’re going to get into the details of things like images, containers, and orchestration. But before we do that, it’s a good idea to show you the big picture.
In this chapter we’ll download an image, start a new container, log in to the new container, run a command inside of it, and then destroy it. This will give you a good idea of what Docker is all about and how some of the major components fit together.
But don’t worry if some of the stuff we do here is totally new to you. We’re not trying to make you experts by the end of this chapter. All we’re doing here is giving you a feel of things - setting you up so that when we get into the details in later chapters, you have an idea of how the pieces fit together.
All you need to follow along with the exercises in this chapter is a single Docker host. This can be any of the options we just installed in the previous chapter. It doesn’t matter if this Docker host is a VM on your laptop, an instance in the public cloud, or bare metal server in your data center. All it needs, is to be running Docker with a connection to the internet. We’ll be showing examples using Linux and Windows!
When you install Docker you get two major components:
- the Docker client
- the Docker daemon (sometimes called server)
The daemon implements the Docker Remote API.
In a default Linux installation the client talks to the daemon via a local IPC/Unix socket at
/var/run/docker.sock. On Windows it listens on a named pipe at
npipe:////./pipe/docker_engine. You can test that the client and daemon are operating and can talk to each other with the
docker version command.
As long as you get a response back from the
Server components you should be good to go. If you are using Linux and get an error response from the Server component, try the command again with
sudo in front of it:
sudo docker version. If it works with
sudo you will need to prefix the remainder of the commands in this chapter with
Now let’s look at images.
Right now, the best way to think of a Docker image is as an object that contains an OS filesystem and an application. It’s not massively different from a virtual machine template. A virtual machine template is essentially a stopped virtual machine. In the Docker world, an image is effectively a stopped container.
docker image ls command on your Docker host.
If you are working from a freshly installed Docker host it will have no images and will look like the output above.
Getting images onto your Docker host is called “pulling”. If you are following along with Linux ,pull the
ubuntu:latest. If you are following along on Windows, pull the
docker image ls command again to see the image you just pulled.
We’ll get into the details of where the image is stored and what’s inside of it in the next chapter. For now it’s enough to understand that an image contains enough of an operating system (OS), as well as all the code to run whatever application it’s designed for. The
ubuntu image that we’ve pulled has a stripped down version of the Ubuntu Linux filesystem including a few of the common Ubuntu utilities. The
microsoft/powershell image pulled in the Windows example contains a Windows Nano Server OS with PowerShell.
It’s also worth noting that each image gets it’s own unique ID. When working with the images you can refer to them using either
IDs or names.
Now that we have an image pulled locally on our Docker host, we can use the
docker container run command to launch a container from it.
Look closely at the output from the commands above. You should notice that your shell prompt has changed. This is because your shell is now attached to the shell of the new container - you are literally inside of the new container!
Let’s examine that
docker container run command.
docker container run tells the Docker daemon to start a new container. The
-it flags tell the daemon to make the container interactive and to attach our current terminal to the shell of the container (we’ll get more specific about this in the chapter on containers). Next, the command tells Docker that we want the container to be based on the
ubuntu:latest image (or the microsoft/powershell:nanoserver image if you’re following along with Windows). Finally, we tell Docker which process we want to run inside of the container. For the Linux example we’re running a Bash shell, for the Windows container were running PowerShell.
ps command from inside of the container to list all running processes.
Inside the Linux container there are only two processes running:
- PID 1. This is the
/bin/bashprocess that we told the container to run with the
docker container runcommand.
- PID 9. This is the
ps -elfcommand/process that we ran to list the running processes.
The presence of the
ps -elf process in the output above could be a bit misleading as it is a short-lived process that dies as soon as the
ps command exits. This means that the only long-running process inside of the container is the
The Windows container has a lot more internal processes running. This is an artifact of the way the Windows Operating System works. Although it is a lot more processes than the Linux container, it is still a lot less processes than are running on the Windows Server host.
Ctrl-PQ to exit the container without terminating it. This will land you back in the shell of your Docker host. You can verify this by looking at your shell prompt.
Now that you are back at the shell prompt of you Docker host, run the
ps command again.
Notice how many more processes are running on your Docker host compared to the long-running process inside of the container.
In a previous step you pressed
Ctrl-PQ to exit from the container. Doing this from inside of a container will exit you from the container without killing it. You can see all of the running containers on your system using the
docker container ls command.
The output above shows a single running container. This is the container that you created earlier. The presence of your container in this output proves that it’s still running. You can also see that it was created 7 minutes ago and has been running for 7 minutes.
Attaching to running containers
You can attach your shell to running containers with the
docker container exec command. As the container from the previous steps is still running let’s connect back to it.
This example references a container called “vigilant_borg”. The name of your container will be different, so remember to substitute “vigilant_borg” with the name or ID of the container running on your Docker host.
This example references a container called “pensive_hamilton”. The name of your container will be different, so remember to substitute “pensive_hamilton” with the name or ID of the container running on your Docker host.
Notice that your shell prompt has changed again. You are back inside the container.
The format of the
docker container exec command is:
docker container exec -options <container-name or container-id> <command>. In our example we used the
-it options to attach our shell to the container’s shell. We referenced the container by name and told it to run the bash shell (PowerShell in the Windows example). We could easily have referenced the container by its ID.
Exit the container again by pressing
Your shell prompt should be back to your Docker host.
docker container ls command again to verify that your container is still running.
Stop the container and kill it using the
docker container stop and
docker container rm commands. Remember to substitute the names/IDs of your own containers.
Verify that the container was successfully deleted by running another
docker container ls command.
Congratulations! You’ve downloaded a Docker image, launched a container from that image, executed a command inside of the container (
ps) and then stopped and deleted the container. This big picture view should help you with the up-coming chapters where we will dig deeper into images and containers.