问题描述
我正在Google Cloud构建中运行CI / CD管道。我的应用具有 web
和 wget
容器。我正在尝试从 wget
I am running my CI/CD pipeline in Google cloud build. My app has web
and wget
containers. I am trying to reach web
from wget
Cloud访问 web
在启动容器作为步骤的同时构建内部使用的 cloudbuild
桥接网络。因此,我期望这些步骤能够使用名称进行通信。但是它失败了。
Cloud build internally used cloudbuild
bridge network while starting containers as steps. So I am expecting these steps to communicate using names. But its failing.
如果我创建了自己的docker bridge netwok,那么他们会进行通讯。
If I create my own docker bridge netwok then they communicating.
我想知道为什么cloudbuild网络无法按预期工作。
I want to know why cloudbuild network is not working as expected.
请让我知道在步骤容器之间建立通信的任何其他方式。
Please let me know if you know any other ways to establish communication between step containers.
cloudbuild.yaml
cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
id: Web server
args: ["run", "-d", "--name", "mani", "manikantanr/hostname_ip"]
- name: 'gcr.io/cloud-builders/wget'
id: wget web mani:8000
args: ["-qO-", "http://mani:8000"]
为了了解cloudbuild的内部结构,我使用了一些docker命令。
To understand the cloudbuild internals I used few docker commands.
debug-cloudbuild.yaml
debug-cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
id: Docker Version
args: ["version"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker info
args: ["info"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker volume ls
args: ["volume", "ls"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker volume inspect homevol
args: ["volume", "inspect", "homevol"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker network ls
args: ["network", "ls"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker network inspect cloudbuild
args: ["network", "inspect", "cloudbuild"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker ps before
args: ["container", "ls", "--no-trunc"]
- name: 'gcr.io/cloud-builders/docker'
id: Web server
args: ["run", "-d", "--name", "mani", "manikantanr/hostname_ip"]
# waitFor: ['-']
- name: 'gcr.io/cloud-builders/wget'
id: wget ipinfo
args: ["-qO-", "https://ipinfo.io"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker ps after
args: ["container", "ls", "--no-trunc"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker inspect mani host network
args: ["inspect", "mani"]
- name: 'gcr.io/cloud-builders/docker'
id: Docker alpine ifconfig inside container
args: ["run", "alpine", "ifconfig"]
- name: 'gcr.io/cloud-builders/wget'
id: wget mani:8000
args: ["-qO-", "http://mani:8000"]
推荐答案
我在设置云构建的集成测试时遇到了类似的问题。我试图从另一个构建器(go-builder)对我的其他容器(通过docker-compose社区构建的容器开始)运行集成测试。
I had a similar issue setting up integration tests on cloud build. I was trying to run integration tests from another builder (go-builder) against my other containers (started through docker-compose community built containers).
在未指定任何网络的情况下docker-compose.yaml,所有容器均在默认网络上启动()。在构建云时,它会创建一个名为 cloudbuild_default 的新网络,并将我的所有容器放置在该网络中。通过强制所有容器通过docker-compose.yaml文件加入 cloudbuild 网络,我能够建立通信并对其进行测试。
Without specifying any networks on docker-compose.yaml, all containers are started on the default network (https://docs.docker.com/compose/networking/). On cloud build, it creates a new network named cloudbuild_default and places all my containers there. By forcing all containers to join cloudbuild network through my docker-compose.yaml file, I was able to establish communications and run my tests against them.
#docker-compose.yaml
networks:
default:
external:
name: cloudbuild
这可能是您的替代配置。希望对您有帮助
This might be an alternate configuration for you. Hope it helps
这篇关于在Google Cloud构建中的两个容器之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!