Book Image

Learn Docker - Fundamentals of Docker 18.x

By : Dr. Gabriel N. Schenker
Book Image

Learn Docker - Fundamentals of Docker 18.x

By: Dr. Gabriel N. Schenker

Overview of this book

Docker containers have revolutionized the software supply chain in small and big enterprises. Never before has a new technology so rapidly penetrated the top 500 enterprises worldwide. Companies that embrace containers and containerize their traditional mission-critical applications have reported savings of at least 50% in total maintenance cost and a reduction of 90% (or more) of the time required to deploy new versions of those applications. Furthermore they are benefitting from increased security just by using containers as opposed to running applications outside containers. This book starts from scratch, introducing you to Docker fundamentals and setting up an environment to work with it. Then we delve into concepts such as Docker containers, Docker images, Docker Compose, and so on. We will also cover the concepts of deployment, orchestration, networking, and security. Furthermore, we explain Docker functionalities on public clouds such as AWS. By the end of this book, you will have hands-on experience working with Docker containers and orchestrators such as SwarmKit and Kubernetes.
Table of Contents (21 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Chapter 7


  1. The three core elements are sandbox, endpoint, and network
  2. Execute this command:
$ docker network create --driver bridge frontend
  1. Run this command:
$ docker container run -d --name n1 \
    --network frontend -p 8080:80 nginx:alpine
$ docker container run -d --name n2 \
    --network frontend -p 8081:80 nginx:alpine

Test that both Nginx instances are up and running:

$ curl -4 localhost:8080
$ curl -4 localhost:8081

You should be seeing the welcome page of Nginx in both cases.

  1. To get the IPs of all attached containers, run:
$ docker network inspect frontend | grep IPv4Address

You should see something similar to the following:

"IPv4Address": "172.18.0.2/16",
"IPv4Address": "172.18.0.3/16",

To get the subnet used by the network, use the following (for example):

$ docker network inspect frontend | grep subnet

You should receive something along the lines of the following (obtained from the previous example):

"Subnet": "172.18.0.0/16",
  1. The host network allows us to run a container in the networking namespace of the host.
  2. Only use this network for debugging purposes or when building a system-level tool. Never use the host network for an application container running production!
  3. The none network is basically saying that the container is not attached to any network. It should be used for containers that do not need to communicate with other containers and do not need to be accessed from outside.
  4. The none network could e.g. be used for a batch process running in a container that only needs access to local resources such as files which could be accessed via a host mounted volume.