Skip to content

Use testcontainers ryuk within docker build RUN command #1274

Closed

Description

@mariusneo

As described in the proof of concept project

https://github.com/mariusneo/dockerized-maven-build

while trying to execute tests that rely on testcontainers library while building a docker image with the docker RUN command

RUN mvn clean test

the following error occurs:

2019-02-25 16:06:46 WARN  ResourceReaper:137 - Can not connect to Ryuk at my.docker.host:32866
java.net.ConnectException: Connection refused (Connection refused)
	at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
	at java.base/java.net.Socket.connect(Socket.java:591)
	at java.base/java.net.Socket.connect(Socket.java:540)
	at java.base/java.net.Socket.<init>(Socket.java:436)
	at java.base/java.net.Socket.<init>(Socket.java:213)
	at org.testcontainers.utility.ResourceReaper.lambda$start$1(ResourceReaper.java:112)
	at java.base/java.lang.Thread.run(Thread.java:834)

NOTE that in the provided example the DOCKER_HOST environment variable is set to a machine different than the one where the docker image is being built.

ARG dockerHost
ENV DOCKER_HOST=${dockerHost}

On the other hand, if in the Dockerfile the environment variable TESTCONTAINERS_RYUK_DISABLED is set to true

ENV TESTCONTAINERS_RYUK_DISABLED="true"

the tests that spawn the docker containers during the tests will run just fine.

My assumption is that the place to perform the change would be in the ResourceReaper class

public static String start(String hostIpAddress, DockerClient client) {
        String ryukImage = TestcontainersConfiguration.getInstance().getRyukImage();
        DockerClientFactory.instance().checkAndPullImage(client, ryukImage);

        List<Bind> binds = new ArrayList<>();
        binds.add(new Bind("//var/run/docker.sock", new Volume("/var/run/docker.sock")));

where the /var/run/docker.sock volume binding is done explicitly to /var/run/docker.sock.
I assume that here would be more appropriate to use the dockerHost from the dockerClientConfig.

See the discussion from #1181

Activity

  1. kiview commented on Feb 26, 2019

    @kiview
    Member

    So after a little bit more investigation it seems running in side the docker build is not the problem, but the remote Docker daemon's host not exposing the Docker socket.

    I assume that here would be more appropriate to use the dockerHost from the dockerClientConfig.

    Not really, since the Ryuk container is already spawned on the correct daemon.

    In which kind of environment are you running this? Some special CI?

  2. mariusneo commented on Feb 26, 2019

    @mariusneo
    Author

    In which kind of environment are you running this? Some special CI?

    I am running the scenario on a homemade CI environment at the companwhere I am employed.

    remote Docker daemon's host not exposing the Docker socket.

    Indeed it is so. The operations engineer handling the remote docker daemon machine was saying that dockerd exposes either tcp or unix sock, reason why the dockerd on the remote machine is only accessible over tcp

    Now I am reading the page

    https://docs.docker.com/engine/reference/commandline/dockerd/

    and see that it is though possible to expose both tcp and unix sockets for the dockerd.

    # listen using the default unix socket, and on 2 specific IP addresses on this host.
    
    $ sudo dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
    

    I'm getting back with a reply tommorow whether this is just a misconfiguration on our home grown CI environment.

    Thanks for the heads up and sorry for the false feature request.

  3. bsideup commented on Feb 26, 2019

    @bsideup
    Member
  4. mariusneo commented on Mar 4, 2019

    @mariusneo
    Author

    Hi guys, I've just tried to run the tests without disabling ryuk (through ENV TESTCONTAINERS_RYUK_DISABLED="true") when the remote docker daemon has the unix socket -H unix:///var/run/docker.sock (along the tcp socket) active and the tests run successfully.
    This means that the issue i've reported is rather linked to our special CI environment.

    Thanks again for the heads up.
    Closing the invalid feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions