Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Mastering Docker, Fourth Edition
  • Table Of Contents Toc
  • Feedback & Rating feedback
Mastering Docker, Fourth Edition

Mastering Docker, Fourth Edition - Fourth Edition

4.3 (4)
close
close
Mastering Docker, Fourth Edition

Mastering Docker, Fourth Edition

4.3 (4)

Overview of this book

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 a significant impact on the world of web development. Mastering Docker shows you how you can ensure that you're keeping up with the innovations it's driving and be sure you're using it to its full potential. This fourth edition not only demonstrates how to use Docker more effectively but also helps you rethink and reimagine what you can achieve with it. You'll start by building, managing, and storing images along with exploring best practices for working with Docker confidently. Once you've got to grips with Docker security, the book covers essential concepts for extending and integrating Docker in new and innovative ways. You'll also learn how to take control of your containers efficiently using Docker Compose, Docker Swarm, and Kubernetes. By the end of this Docker book, you’ll 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.
Table of Contents (22 chapters)
close
close
1
Section 1: Getting Up and Running with Docker
8
Section 2: Clusters and Clouds
16
Section 3: Best Practices

Using Docker commands

You should already be familiar with these Docker commands. However, it's worth going through them to ensure you know all. 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.

Tip

A while ago, Docker restructured their command-line client into more logical groupings of commands, as the number of features provided by the client multiplies and commands start to cross over each other. Throughout this book, we will be using this structure rather than some of the shorthand that still exists within the client.

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. We will be looking at this in more detail in Chapter 4, Managing Containers. 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:

Figure 1.12 – Output for docker container run hello-world

Figure 1.12 – Output for docker container run hello-world

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

Important note

NGINX is an open source web server that can be used as a load balancer, mail proxy, reverse proxy, and even an HTTP cache.

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:

Figure 1.13 – Output of docker image pull nginx on Linux

Figure 1.13 – Output of docker image pull nginx on Linux

Important note

You may notice that the Linux and macOS screens at first glance look similar. That is because I am using a remote Linux server, and we will look more at how to do this in a later chapter.

This is the result on macOS:

Figure 1.14 – Output of docker image pull nginx on macOS

Figure 1.14 – Output of docker image pull nginx on macOS

And this is how it looks on Windows:

Figure 1.15 – Output of docker image pull nginx on Windows

Figure 1.15 – Output of docker image pull nginx 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 a very different experience on each platform too. Traditionally, this has been one of the reasons for the difference in local development environments as people would need to download a platform-specific installer and configure the service for the platform they are running. Also, in some cases there could be feature differences between the platforms.

Now that we have a foundation in Docker commands, let's cast a wider net and look at its container ecosystem.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Mastering Docker, Fourth Edition
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon