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

You're reading from   Mastering Docker Unlock new opportunities using Docker's most advanced features

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher
ISBN-13 9781789616606
Length 426 pages
Edition 3rd Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Scott Gallagher Scott Gallagher
Author Profile Icon Scott Gallagher
Scott Gallagher
Russ McKendrick Russ McKendrick
Author Profile Icon Russ McKendrick
Russ McKendrick
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Docker Overview 2. Building Container Images FREE CHAPTER 3. Storing and Distributing Images 4. Managing Containers 5. Docker Compose 6. Windows Containers 7. Docker Machine 8. Docker Swarm 9. Docker and Kubernetes 10. Running Docker in Public Clouds 11. Portainer - A GUI for Docker 12. Docker Security 13. Docker Workflows 14. Next Steps with Docker 15. Assessments 16. Other Books You May Enjoy

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.

Docker has restructured their command-line client into more logical groupings of commands, as the number of features provided by the client grows quickly and commands start to cross over each other. Throughout this book, we will be using the new structure.

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

$ docker help

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

$ docker <COMMAND> --help

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

$ 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 a 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 command 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 the result on 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

As you can see, the experience of running a simple nginx container on all three of the hosts on which we have installed Docker is exactly the same. As am I sure you can imagine, trying to achieve this without something like Docker across all three platforms is a challenge, and also a very different experience on each platform. Traditionally, this has been one of the reasons for the difference in local development environments.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime