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

那年仲夏 提交于 2019-12-07 03:16:29

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/28562704/how-to-link-docker-containers-on-container-vm-with-an-manifest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!