
- 300 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Learning Docker - Second Edition
About this book
Docker lets you create, deploy, and manage your applications anywhere at anytime – flexibility is key so you can deploy stable, secure, and scalable app containers across a wide variety of platforms and delve into microservices architectureAbout This Book• This up-to-date edition shows how to leverage Docker's features to deploy your existing applications• Learn how to package your applications with Docker and build, ship, and scale your containers• Explore real-world examples of securing and managing Docker containersWho This Book Is ForThis book is ideal for developers, operations managers, and IT professionals who would like to learn about Docker and use it to build and deploy container-based apps. No prior knowledge of Docker is expected.What You Will Learn• Develop containerized applications using the Docker version 17.03• Build Docker images from containers and launch them• Develop Docker images and containers leveraging Dockerfiles• Use Docker volumes to share data• Get to know how data is shared between containers• Understand Docker Jenkins integration• Gain the power of container orchestration• Familiarize yourself with the frequently used commands such as docker exec, docker ps, docker top, and docker statsIn DetailDocker is an open source containerization engine that offers a simple and faster way for developing and running software. Docker containers wrap software in a complete filesystem that contains everything it needs to run, enabling any application to be run anywhere – this flexibily and portabily means that you can run apps in the cloud, on virtual machines, or on dedicated servers.This book will give you a tour of the new features of Docker and help you get started with Docker by building and deploying a simple application. It will walk you through the commands required to manage Docker images and containers. You'll be shown how to download new images, run containers, list the containers running on the Docker host, and kill them.You'll learn how to leverage Docker's volumes feature to share data between the Docker host and its containers – this data management feature is also useful for persistent data. This book also covers how to orchestrate containers using Docker compose, debug containers, and secure containers using the AppArmor and SELinux security modules.Style and approachThis step-by-step guide will walk you through the features and use of Docker, from Docker software installation to the impenetrable security of containers.
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
Orchestrating Containers
- Linking containers
- Orchestrating containers
- Orchestrating containers using the docker-compose tool
Docker inbuilt service discovery
- Let's begin by creating a user-defined bridge network, mybridge, using the following command:
$ sudo docker network create mybridge
- Inspect the newly created network to understand the subnet range and gateway IP:
$ sudo docker network inspect mybridge
[
{
"Name": "mybridge",
"Id": "36e5e088543895f6d335eb92299ee8e118cd0610e0d023f7c42e6e603b935e17",
"Created":
"2017-02-12T14:56:48.553408611Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
- Now, let's create a container by attaching it to the mybridge network, as shown here:
$ sudo docker container run \
-itd --net mybridge --name testdns ubuntu
- Continue to list the IP address assigned to the container, as illustrated here:
$ sudo docker container inspect --format \
'{{.NetworkSettings.Networks.mybridge.IPAddress}}' \
testdns
172.18.0.2
- Having got the IP address of the container, let's look into the content of the /etc/resolv.conf file of the container using the docker container exec subcommand, as shown here:
$ sudo docker container exec testdns \
cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
- As a final step, let's ping the testdns container using the busybox image. We picked the busybox image here because the ubuntu image is shipped without the ping command:
$ sudo docker container run --rm --net mybridge \
busybox ping -c 2 testdns
PING testdns (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64
time=0.085 ms
64 bytes from 172.18.0.2: seq=1 ttl=64
time=0.133 ms
--- testdns ping statistics ---
2 packets transmitted, 2 packets received,
0% packet loss
round-trip min/avg/max = 0.085/0.109/0.133 ms
Linking containers
--link <container>:<alias>
- NAME: This is the first category of environment variables. These variables take the form of <ALIAS>_NAME, and they carry the recipient container's hierarchical name as their value. For instance, if the source container's alias is src and the recipient container's name is rec, then the environment variable and its value will be SRC_NAME=/rec/src.
- ENV: This is the second category of environment variables used to export the environment variables configured in the source container by the -e option of the docker run subcommand or the ENV instruction of the Dockerfile. This type of an environment variable takes the form of <ALIAS>_ENV_<VAR_NAME>. For instance, if the source container's alias is src and the variable name is SAMPLE, then the environment variable will be SRC_ENV_SAMPLE.
- PORT: This is the final and third category of environment variables that is used to export the connectivity details of the source container to the recipient. Docker creates a bunch of variables for each port exposed by the source container through the -p option of the docke...
Table of contents
- Title Page
- Copyright
- Credits
- About the Authors
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Preface
- Getting Started with Docker
- Handling Docker Containers
- Building Images
- Publishing Images
- Running Your Private Docker Infrastructure
- Running Services in a Container
- Sharing Data with Containers
- Orchestrating Containers
- Testing with Docker
- Debugging Containers
- Securing Docker Containers
- The Docker Platform – Distinct Capabilities and Use Cases