Can Testcontainers join existing network?

2k views Asked by At

I wish to create a network via docker-compose (via DockerComposeContainer) and have another container (created via ImageFromDockerfile) join that same network. Is this possible?

Asked another way, can ImageFromDockerfile join an existing network? (For me the order is crucial, because when i start my image it needs to connect to all the services running through compose)

The moving parts I have tried include:

  1. The docker compose file
version: '3.6'

services:
  vault:
    image: docker.x.com/x/vault:123-ytr
    ports:
      - 8200:8200
    networks:
      - gateway
    environment:
      - APP_NAME=requestlogidentityconsumer

networks:
  gateway:
    name: damo
  1. Executing above compose file via DockerComposeContainer (incl. create damo network)

  2. Attempt to build and run rlic-container and have it join damo n/w

    Network network =
        Network.builder().createNetworkCmdModifier(cmd -> cmd.withName("damo")).build();

    new GenericContainer(
            new ImageFromDockerfile("rlic-container", true)
                .withFileFromFile("Dockerfile", DOCKER_FILE_PATH.toFile()))
        .withNetwork(network)
        .start();

When I run step 3 i get:

Caused by: com.github.dockerjava.api.exception.ConflictException: {"message":"network with name damo already exists"}

Which makes sense (in so far as network does exist from step 2), and ties back to my question of; can i write step 3 such that it joins an existing network?

Thanks

0

There are 0 answers