【发布时间】:2020-02-13 12:59:54
【问题描述】:
我正在使用 TestContainers 来运行 dgraph。
这是我的测试代码:
package net.dgraph.java.client
import io.dgraph.DgraphAsyncClient
import io.dgraph.DgraphClient
import org.testcontainers.containers.DockerComposeContainer
import org.testcontainers.containers.GenericContainer
import org.testcontainers.spock.Testcontainers
import spock.lang.Shared
import spock.lang.Specification
import java.time.Duration
import java.time.temporal.ChronoUnit
@Testcontainers
public class DGraphTest extends Specification {
private SyncSigmaDgraphClient syncClient
private AsyncSigmaDGraphClient asyncClient
private static address
static DockerComposeContainer compose
def setup() {
syncClient = SigmaDgraphClientBuilder
.create()
.withHost(address)
.withPort(port1)
.buildSync()
}
static {
compose =
new DockerComposeContainer(
new File("src/test/resources/docker-compose.yaml"))
compose.start()
this.address = compose.getServiceHost("dgraph", 8080)
this.port1 = compose.getServicePort("dgraph",8080)
}
我的 docker-compose.yaml 文件看起来像:
version: "3.2"
services:
zero:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 5080:5080
- 6080:6080
restart: on-failure
command: dgraph zero --my=zero:5080
alpha:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 8080:8080
- 9080:9080
restart: on-failure
command: dgraph alpha --my=alpha:7080 --lru_mb=2048 --zero=zero:5080
ratel:
image: dgraph/dgraph:latest
ports:
- 8000:8000
command: dgraph-ratel
我的 docker 版本是 Docker version 19.03.2, build 6a30dfc,我的 docker-compose 版本是 docker-compose version 1.24.1, build 4667896b
。
但是我收到以下错误:
[main] ERROR ???? [docker/compose:1.8.0] - Log output from the failed container:
Version in "src/test/resources/docker-compose.yaml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
我觉得有趣的部分是错误日志显示 docker/compose:1.8.0,这是一个比我当前运行的版本更旧的版本。我曾尝试在我的 docker-compose 中更改版本,但这似乎不起作用。我查看了其他具有相同错误的问题,但他们的解决方案均无效。我觉得 TestContainer 库使用的 docker-compose 比我旧版本,但如果这是问题,那么我不知道如何解决它。
【问题讨论】:
标签: java docker docker-compose spock testcontainers