It will be reachable with its name search docker run d name search net dev

It will be reachable with its name search docker run

This preview shows page 242 - 250 out of 354 pages.

It will be reachable with its name, search . $ docker run -d --name search --net dev elasticsearch 8abb80e229ce8926c7223beb69699f5f34d6f1d438bfc5682db893e798046863 The Container Network Model Docker Fundamentals d7590d1 242 © 2015 Docker Inc
Image of page 242
Communication between containers Now, create another container on this network. $ docker run -ti --net dev alpine sh [email protected]:/# From this new container, we can resolve and ping the other one, using its assigned name: / # ping search PING search (172.18.0.2) 56(84) bytes of data. 64 bytes from search.dev (172.18.0.2): icmp_seq=1 ttl=64 time=0.221 ms 64 bytes from search.dev (172.18.0.2): icmp_seq=2 ttl=64 time=0.114 ms 64 bytes from search.dev (172.18.0.2): icmp_seq=3 ttl=64 time=0.114 ms ^C --- search ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.114/0.149/0.221/0.052 ms [email protected]:/# The Container Network Model Docker Fundamentals d7590d1 243 © 2015 Docker Inc
Image of page 243
Resolving container addresses In Docker Engine 1.9, name resolution is implemented with /etc/hosts , and updating it each time containers are added/removed. [[email protected] /]# cat /etc/hosts 172.18.0.3 0ecccdfa45ef 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.18.0.2 search 172.18.0.2 search.dev In Docker Engine 1.10, this has been replaced by a dynamic resolver. (This avoids race conditions when updating /etc/hosts .) The Container Network Model Docker Fundamentals d7590d1 244 © 2015 Docker Inc
Image of page 244
Connecting multiple containers together Let's try to run an application that requires two containers. The first container is a web server. The other one is a redis data store. We will place them both on the dev network created before. The Container Network Model Docker Fundamentals d7590d1 245 © 2015 Docker Inc
Image of page 245
Running the web server The application is provided by the container image jpetazzo/ trainingwheels . We don't know much about it so we will try to run it and see what happens! Start the container, exposing all its ports: $ docker run --net dev -d -P jpetazzo/trainingwheels Check the port that has been allocated to it: $ docker ps -l The Container Network Model Docker Fundamentals d7590d1 246 © 2015 Docker Inc
Image of page 246
Test the web server If we connect to the application now, we will see an error page: This is because the Redis service is not running. This container tries to resolve the name redis . Note: we're not using a FQDN or an IP address here; just redis . The Container Network Model Docker Fundamentals d7590d1 247 © 2015 Docker Inc
Image of page 247
Start the data store We need to start a Redis container. That container must be on the same network as the web server. It must have the right name ( redis ) so the application can find it. Start the container: $ docker run --net dev --name redis -d redis The Container Network Model Docker Fundamentals d7590d1 248 © 2015 Docker Inc
Image of page 248
Test the web server again If we connect to the application now, we should see that the app is working correctly: When the app tries to resolve redis , instead of getting a DNS error, it gets the IP address of our Redis container.
Image of page 249
Image of page 250

You've reached the end of your free preview.

Want to read all 354 pages?

  • Fall '17
  • NA
  • Business

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes