Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link docker containers on Container VM with an manifest?

TLDR: Is it possible to link two containers with the container manifest?

I'm trying to port the Guestbook Sample app from the Google Container Engine docs to a container vm. I'm having troubles to connect the two container vms so the web app can access the redis service.

It works, if I'm using the docker command line on the instance:

start the instance and ssh into it:

gcloud compute instances create guestbook-vm --image container-vm --machine-type g1-small 
gcloud ssh guestbook-vm

create the containers:

sudo docker run -d --name redis -p 6379:6379 dockerfile/redis
sudo docker run -d --name guestbook -p 3000:80 --link redis:redis -e "REDIS_MASTER_SERVICE_HOST=redis" -e "REDIS_MASTER_SERVICE_PORT=6379" brendanburns/php-redis

I'm using the --link to connect the guestbook to the redis container. Can this also be accomplished with the container manifest?

this is my start command:

gcloud compute instances create guestbook-vm --image container-vm --machine-type g1-small --metadata-from-file google-container-manifest=containers.yaml

EDIT: Solution from Alex to use 127.0.0.1 works fine, so that's the right containers.yaml:

version: v1beta2
containers:
  - name: redis
    image: dockerfile/redis
    ports:
      - name: redis-server
        containerPort: 6379
        hostPort: 6379
  - name: guestbook
    image: brendanburns/php-redis
    ports:
      - name: http-server
        containerPort: 80
        hostPort: 3000
    env:
      - name: REDIS_MASTER_SERVICE_HOST
        value: 127.0.0.1
      - name: REDIS_MASTER_SERVICE_PORT
        value: 6379
like image 833
Paul Avatar asked Feb 17 '15 13:02

Paul


1 Answers

There is no link parameter available in the container manifest, so unfortunately you can't do it that way.

However, have you tried just setting the REDIS_MASTER_SERVICE_HOST environment variable to 127.0.0.1? I believe that should allow the frontend container to talk to the redis container through the standard networking stack.

like image 140
Alex Robinson Avatar answered Oct 04 '22 17:10

Alex Robinson