常见错误解析

1. 使用docker-compose.yaml文件中使用变量替代,但是环境变量中没有设置该变量。

比如,在docker-compose.yaml文件使用了变量¥{TEST1_PORT}作为端口映射,但是,主机shell的环境变量中没有该变量,运行命令:

docker-compose up

将会出现以下错误信息:

WARNING: The TEST1_PORT variable is not set. Defaulting to a blank string.
ERROR: Validation failed in file './docker-compose.yaml', reason(s):
services.compose_test2.ports is invalid: Invalid port ":8000", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]

解决办法,在shell环境变量中设置该变量:

$TEST1_PORT=4000
$export TEST1_PORT

2. swarm集群中使用docker-compose.yaml,未设置容器的网络

使用docker-compose将容器运行在swarm上,必须为每个容器指定网络,如果不指定网络信息,将会出现以下信息:

$./docker-compose -H 192.168.48.70:4000 up
Creating network "test_default" with the default driver
ERROR: 500 Internal Server Error: failed to parse pool request for address space "GlobalDefault" pool "" subpool "": cannot find address space GlobalDefault (most likely the backing datastore
 is not configured)

解决办法,为没有添加网络信息的容器添加网络信息,比如,添加如下信息:

network_mode: "bridge"

3. 当docker-compose.yaml中容器较多时,启动容器时出现“Read timed out”错误。

当docker-compose.yaml文件中定义了较多的容器,使用命令docker-compose up启动容器时,有时会出现其中的部分容器Read timed out错误,如下所示:

ERROR: for CS5_AS_CRDTTRANS1  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

ERROR: for CS5_AS_PRODTRANS1  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60

ERROR: for CS5_AS_SECUTRANS2  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

ERROR: for CS5_AS_CTRADE1  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).

产生这个问题的原因,目前还不能够确定,猜测有如下原因:

第一,有可能是etcd的问题,我们使用了3台etcd,当减为2台时,该问题可解决。

第二,COMPOSE_HTTP_TIMEOUT设置问题,当COMPOSE_HTTP_TIMEOUT设置为较大数字时,该问题出现频率会降低,但是还有几率出现,可使用如下方式设置COMPOSE_HTTP_TIMEOUT:

COMPOSE_HTTP_TIMEOUT=2000 docker-compose up

第三,docker-compose本身的缺陷,其处理容器较多时可能产生这个问题,只能等待其更新。

4. 执行命令“docker-compse up”时,提示不支持ipv4_address。

docker-compose版本过低,更新版本为1.7.0以上。

感谢

感谢您的阅读,有些问题的解决办法不是最好的,或者说是有问题的,若您有更好的办法或者有新的问题,请发送邮件至[email protected]。作者会及时更新文档并和您探讨您的问题!

Thank You!