2
我在OSX上使用码头1.12和码头构成1.12。无法连接到容器与码头构成
我创建了运行两个集装箱码头工人,compose.yml文件:
- 第一,命名火花,构建并运行一个应用程序sparkjava
第二,命名的行为,运行一些功能测试在由第一个容器暴露的API上。
version: "2" services: behave: build: context: ./src/test container_name: "behave" links: - spark depends_on: - spark entrypoint: ./runtests.sh spark:9000 spark: build: context: ./ container_name: "spark" ports: - "9000:9000"
由于recommended by Docker Compose documentation,我用一个简单的shell脚本来测试,如果火花服务器已准备就绪。该脚本名称为runtest.sh,并运行到名为“behave”的容器中。它由docker-compose发布(见上):
#!/bin/bash
# This scripts waits for the API server to be ready before running functional tests with Behave
# the parameter should be the hostname for the spark server
set -e
host="$1"
echo "runtests host is $host"
until curl -L "http://$host"; do
>&2 echo "Spark server is not ready - sleeping"
sleep 5
done
>&2 echo "Spark server is up - starting tests"
behave
```
DNS解析似乎不起作用。 curl向spark.com发出请求,而不是对名为“spark”的容器的请求。
UPDATE:
通过设置一个别名,我的链接(links: -spark:myserver
),我见过的DNS解析不是由码头工人做:我收到一条错误消息从公司网络设备(我使用Docker for Mac从企业代理的后面运行此操作)。下面是输出的摘录:
Recreating spark
Recreating behave
Attaching to spark, behave
behave | runtests host is myserver:9000
behave | % Total % Received % Xferd Average Speed Time Time Time Current
behave | Dload Upload Total Spent Left Speed
100 672 100 672 0 0 348 0 0:00:01 0:00:01 --:--:-- 348
behave | <HTML><HEAD>
behave | <TITLE>Network Error</TITLE>
behave | </HEAD>
behave | <BODY>
behave | ...
behave | <big>Network Error (dns_unresolved_hostname)</big>
behave | Your requested host "myserver" could not be resolved by DNS.
behave | ...
behave | </BODY></HTML>
behave | Spark server is up - starting tests
FWIW,我不认为你需要的'links'条目。 *链接允许您定义额外的别名,通过它可以从另一个服务访问服务。* – R0MANARMY
这不是我在这里阅读的:https://docs.docker.com/compose/compose-file/#/links。然而,我尝试过,但它并没有解决我的问题。 –
我删除了我的答案,因为它不再适用于您编辑的问题。考虑包括脚本输出的日志,以及其他命令来测试DNS(例如ping)以将问题隔离到DNS或卷曲。 – BMitch