Learning Docker - Second Edition
Jeeva S. Chelladhurai, Vinod Singh, Pethuru Raj
- 300 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Learning Docker - Second Edition
Jeeva S. Chelladhurai, Vinod Singh, Pethuru Raj
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
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...