Docker Container Links (James Lee)

Screen Shot 2016-10-14 at 12.19.19 PM.png

    1. how to connect services that run in different containers
    2. (in Docker Image section, wrote Dockerfile that had Flask (aka dockerapp) service in one container using local memory). What if want 2+ services? Use multiple containers & link
    3. Recipient container can get information FROM source container
      1. Links established using --link flag AND container names
      2. Docker creates a secure tunnel that doesn’t need to expose any ports externally on the containers (note, do not need to use -p flag when spinning up source container - redis)
      1. Modify dockerapp’s Dockerfile so that dockerapp installs not just Flask library but also redis client library (note, this is just the library. NOT the images). Redis service will be built from its own image. We need this so Dockerapp has a redis client (can talk to redis service/container).

Dockerapp Dockerfile:

FROM python:3.5 → base image is python:3.5

RUN pip install Flask==0.11.1 redis 2.10.5 → installs Flask libr & redis client libr (NOT img)

RUN useradd -ms /bin/bash admin → adds new user, admin.

USER admin -ms: adds default home dir for new user

WORKDIR /app /bin/bash: sets default shell to “bash”

COPY app /app

CMD ["python", "app.py"]

      1. Start redis service by downloading existing “official” redis image from Docker Hub
        1. $ docker run -d --name redis redis:3.2.0 → note named container “redis”
      2. Build dockerapp image from Dockerfile.
        1. $ docker build -t dougwells/dockerapp:v0.3.1 .
        2. Note name it “tag it” dougwells/dockerapp:v0.3.1
      3. Run dockerapp container & link to redis (note: redis container is already running)
        1. docker run -d -p 3000:5000 --link redis dougwells/dockerapp:v0.3.1
          1. (note: secure tunnel between containers. No external ports exposed to link containers. -p flag is URL for app. No -p when spun up redis container)
      4. Look up docker-machine’s IP ($ docker-machine ls). Can visit dockerapp at that IP on port 3000 (set above)
      1. To see IP of containers, log into the running recipient container (dockerapp). Mapping of host IP addresses is in /etc/hosts file
        1. $ docker exec -it <cont_id> bash

/: $ cd .. → move up to root directory

/: ls → see all directories (want etc/hosts

/ more etc/hosts → open hosts file inside etc directory

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

172.17.0.3 redis 7007a28ed576 → container_id

172.17.0.2 7a7bb4e21e6a

        1. Inspect redis container
          1. $ docker inspect redis

"Networks": {

"bridge": { "Gateway": "172.17.0.1",

"IPAddress": "172.17.0.3",

        1. Can also verify redis ip or 172.17.03 by logging into running dockerapp container & pinging redis
          1. $ docker exec -it 7a7 bash

/# ping redis note: 172.17.0.3

→ 64 bytes from 172.17.0.3: icmp_seq=0 ttl=64 time=0.106 ms

results matching ""

    No results matching ""