简体   繁体   中英

Docker-Compose version is unsupported

I'm using TestContainers to run dgraph.

Here is my test code:

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)
}

And my docker-compose.yaml file looks like:

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

My docker version is Docker version 19.03.2, build 6a30dfc and my docker-compose version is docker-compose version 1.24.1, build 4667896b .

However I get the following error:

[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.

One part I find interesting is that the error log is showing docker/compose:1.8.0, which is an older version than the one I am currently running. I have tried changing versions in my docker-compose but that doesn't seem to work. I have looked at other questions that have the same error, and none of their solutions work. I feel like the TestContainer library uses an older version of docker-compose than I do, but if this is the issue then I do not know how to fix it.

I believe you want local compose mode:

compose =
        new DockerComposeContainer(
                new File("src/test/resources/docker-compose.yaml")).withLocalCompose(true)

See the local compose mode documentation for more details:

You can override Testcontainers' default behaviour and make it use a docker-compose binary installed on the local machine. This will generally yield an experience that is closer to running docker-compose locally, with the caveat that Docker Compose needs to be present on dev and CI machines.

This was the method I ultimately went with:

I used Network.newNetwork() to tie the zero and alpha instance together. I used debugging and docker logs to see the message that dgraph zero needs to wait for in order for it to start up successfully.

 static {
    Network network = Network.newNetwork()
    dgraph_zero = new GenericContainer<>("dgraph/dgraph")
            .withExposedPorts(5080)
            .withNetworkAliases("zero")
            .withStartupTimeout(Duration.of(1, ChronoUnit.MINUTES))
            .withCommand("dgraph zero --my=zero:5080")
            .withNetwork(network)
            .waitingFor(Wait.forLogMessage('.* Updated Lease id: 1.*\\n',1))
    dgraph_zero.start()

  dgraph_alpha = new GenericContainer<>("dgraph/dgraph")
        .withExposedPorts(9080)
        .withStartupTimeout(Duration.of(1, ChronoUnit.MINUTES))
        .withNetworkAliases("alpha")
        .withCommand("dgraph alpha --my=alpha:7080 --lru_mb=2048 --zero=zero:5080")
        .withNetwork(network)
        .waitingFor(Wait.forLogMessage(".*Server is ready.*\\n",1))
    dgraph_alpha.start()

    this.address = dgraph_alpha.containerIpAddress
    this.port1 = dgraph_alpha.getMappedPort(9080)

    ManagedChannel channel = ManagedChannelBuilder
            .forAddress(address,port1)
            .usePlaintext()
            .build();
    DgraphGrpc.DgraphStub stub = DgraphGrpc.newStub(channel);
    this.dgraphclient = new DgraphClient(stub) ;
    Transaction txn = this.dgraphclient.newTransaction();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM