不能用docker-compose连接到容器

我在OSX上使用docker 1.12和docker-compose 1.12。

我创build了一个运行两个容器的docker-compose.yml文件:

  • 第一个命名为spark,构build并运行sparkjava应用程序
  • 第二个,名为behave,对第一个容器暴露的API运行一些functiontesting。

    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" 

按照Docker Compose文档的build议 ,我使用一个简单的shell脚本来testingspark服务器是否准备就绪。 该脚本名称为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 ``` 

DNSparsing似乎不起作用。 curl向spark.com发出请求,而不是对名为“spark”的容器的请求。

更新:

通过为我的链接设置一个别名( links: -spark:myserver ),我已经看到了DNSparsing不是由Docker完成的:我收到来自公司networking设备的错误消息(我从公司代理,用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 

为了解决这个问题,我添加了一个环境variablesno_proxy作为我想要join的容器的名字。

在容器的dockerfile文件中,我有:

 ENV http_proxy=http://proxy.mycompany.com:8080 ENV https_proxy=http://proxy.mycompany.com:8080 ENV no_proxy=127.0.0.1,localhost,spark