Book Image

Mastering Docker - Second Edition

By : Russ McKendrick, Scott Gallagher
Book Image

Mastering Docker - Second Edition

By: Russ McKendrick, Scott Gallagher

Overview of this book

<p>Docker has been a game-changer when it comes to how modern applications are deployed and architectured. It has now grown into a key driver of innovation beyond system administration, with an impact on the world of web development and more. But how can you make sure you're keeping up with the innovations it's driving? How can you be sure you're using it to its full potential?</p> <p>This book shows you how; it not only demonstrates how to use Docker more effectively, it also helps you rethink and reimagine what's possible with Docker.</p> <p>You will also cover basic topics such as building, managing and storing images along with best practices to make you confident before delving more deeply into Docker security.</p> <p>You'll find everything related to extending and integrating Docker in new and innovative ways. Docker Swarm and Docker Compose will help you take control of your containers in an efficient way.</p> <p>By the end of the book, you will have a broad and detailed sense of exactly what's possible with Docker and how seamlessly it fits in with a range of other platforms and tools.</p>
Table of Contents (21 chapters)
Title Page
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Index

The Docker command-line client


Now that we have Docker installed, let's look at some Docker commands that you should be familiar with already. We will start with some common commands and then take a peek at the commands that are used for the Docker images. We will then take a dive into the commands that are used for the containers.

Note

Docker recently restructured their command-line client into more logical groupings of commands due to the number of features provided by Docker growing quickly and commands starting to cross over each other. Throughout this book, we will be using the new structure. For more information on the command-line client changes, read the following blog post: https://blog.docker.com/2017/01/whats-new-in-docker-1-13/

The first command we will be taking a look at will be one of the most useful commands not only in Docker but in any command-line utility you use: thehelpcommand. It is run simply like this:

$ docker help

This command will give you a full list of all the Docker commands at your disposal and a brief description of what each command does. For further help with a particular command, you can run the following:

$ docker <COMMAND> --help

Next up, let's run the hello-world container. To do this, simply run:

$ docker container run hello-world

It doesn't matter what host you are running Docker on, the same thing will happen on Linux, macOS, and Windows. Docker will download the hello-world container image and then execute it, and once it's executed, the container will be stopped.

Your Terminal session should look like the following:

Let's try something a little more adventurous; let's download and run an NGINX container by running the following two commands:

$ docker image pull nginx
$ docker container run -d --name nginx-test -p 8080:80 nginx

The first of the two commands downloads the NGINX container image, and the second launches a container in the background called nginx-test using the nginx image we pulled. It also maps port 8080 on our host machine to port 80 on the container, making it accessible to our local browser at http://localhost:8080/.

As you can see from the following screenshots, the command and results are exactly the same on all three OS types. Here we have Linux:

This is macOS:

And this is how it looks on Windows:

In the following three chapters, we will look at using the Docker command-line client in more detail; for now, let's stop and remove our nginx-test container by running the following:

$ docker container stop nginx-test
$ docker container rm nginx-test