如何使用清单将容器VM上的Docker容器链接? [英] How to link docker containers on Container VM with an manifest?

查看:118
本文介绍了如何使用清单将容器VM上的Docker容器链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:是否可以将两个容器与容器清单链接?

我正在尝试移植Guestbook Sample应用程序从Google Container Engine文档容器vm 。我在连接两个容器虚拟机时遇到麻烦,因此Web应用程序可以访问redis服务。

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.

如果我在docker命令行上使用了实例:

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

启动该实例并ssh进入该实例:

start the instance and ssh into it:

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

创建容器:

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

我正在使用--link将留言簿连接到redis容器。 这也可以通过容器清单来完成吗?

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

这是我的启动命令:

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

编辑:Alex使用127.0.0.1的解决方案效果很好,因此这是正确的容器。 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


推荐答案

容器清单中没有可用的链接参数,因此很遗憾,您不能那样做。

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

但是,您是否尝试过将REDIS_MASTER_SERVICE_HOST环境变量设置为127.0.0.1?我认为应该允许前端容器通过标准网络堆栈与redis容器进行对话。

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.

这篇关于如何使用清单将容器VM上的Docker容器链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆