Skip to content

Cannot Use testcontainers with Isolated Containers #712

Closed

Description

@schrieveslaach

I do have a docker setup, providing container isolation with a user namespace. Following configuration:

/etc/docker/daemon.json

{
    "userns-remap": "default"
}

/etc/subuid

dockremap:1476256:65536

/etc/subgid

dockremap:1476256:65536

When I use mvn test which tries to start containers, I get following error (cannot connect to Ryuk):

[main] INFO org.testcontainers.DockerClientFactory - Docker host IP address is localhost
[main] INFO org.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 18.05.0-ce
  API Version: 1.37
  Operating System: Arch Linux
  Total Memory: 3948 MB
[testcontainers-ryuk] WARN org.testcontainers.utility.ResourceReaper - Can not connect to Ryuk at localhost:32770
java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)
        at org.testcontainers.utility.ResourceReaper.lambda$start$2(ResourceReaper.java:119)
        at java.lang.Thread.run(Thread.java:748)
[testcontainers-ryuk] WARN org.testcontainers.utility.ResourceReaper - Can not connect to Ryuk at localhost:32770
java.net.ConnectException: Verbindungsaufbau abgelehnt (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at java.net.Socket.<init>(Socket.java:434)
        at java.net.Socket.<init>(Socket.java:211)
        at org.testcontainers.utility.ResourceReaper.lambda$start$2(ResourceReaper.java:119)
        at java.lang.Thread.run(Thread.java:748)

I assume that the ryuk container must be started with the command line option --userns=host (docker ignores user namespaces).

Is it possible to integrate this commandline option?

Activity

  1. kiview commented on Jun 12, 2018

    @kiview
    Member

    AFAIK docker-java doesn't suport user namespaces ATM.

  2. nathanburrell commented on Sep 28, 2018

    @nathanburrell

    Rather than disabling userns remapping on the ryuk container, we can investigate why the ryuk container cant run with that feature enabled as that would be the better fix.

    As some environments may never ever allow a user to turn of the remapping feature for a container. As some cloud CI/CD providers (such as bitbucket pipelines and others) run in a multi tenanted environment and have user namespace remapping always enabled for security purposes.

  3. bsideup commented on Sep 28, 2018

    @bsideup
    Member

    @nathanburrell is it possible to turn it on locally on Mac? Then I can experiment with it locally and maybe figure out why it doesn't work :)

  4. nathanburrell commented on Sep 28, 2018

    @nathanburrell

    It sure is, you can specify daemon args following the steps here

    https://docs.docker.com/v17.12/docker-for-mac/#daemon-tab

    The Arg you want to provide is
    --userns-remap=default

    More information about user namespace remapping is here https://docs.docker.com/engine/security/userns-remap/

  5. nathanburrell commented on Oct 9, 2018

    @nathanburrell

    Any updates on this?

    Over the coming months we will be removing the exclusion list as it leaves potential security holes within our product, and I want to ensure test containers still works with pipelines when that time comes.

  6. kiview commented on Oct 9, 2018

    @kiview
    Member

    I'll try to see if I can reproduce it locally on Linux when setting the flag on the daemon.
    The actual ryuk implementation is pretty slim, so I wonder where the problem comes from:
    https://github.com/testcontainers/moby-ryuk/blob/master/main.go

  7. schrieveslaach commented on Oct 10, 2018

    @schrieveslaach
    Author

    @kiview, if you have a new SNAPSHOT version, I can test it on my machine.

  8. rnorth commented on Dec 13, 2018

    @rnorth
    Member

    I was trying to reproduce the other day so that we can look into why - however, I had trouble with the userns-remap setting on Docker for Mac. It seems that setting this in the daemon JSON configuration causes the daemon to fail to start up.

    I haven't yet had time to try this in another context (e.g. with docker-machine).

    Sorry for there being no progress made on this ticket so far. If anybody has ability to diagnose why this setting is incompatible with Ryuk, we'd be keen to get your input.

  9. jrehwaldt commented on Dec 14, 2018

    @jrehwaldt

    Suppose the issue with bitbucket pipeline is indeed the same you can test it against their dockerized pipeline runner as follows:

    docker run --privileged --name bitbucket-docker -d -p 127.0.0.1:12375:2375 --memory=1g --memory-swap=1g --memory-swappiness=0  atlassian/pipelines-docker-daemon:prod-stable
    set DOCKER_HOST=tcp://127.0.0.1:12375
    // run testcontainers mounting against DOCKER_HOST
    

    You should see the same log as posted in the issue description.

  10. rnorth commented on Dec 15, 2018

    @rnorth
    Member

    Ah, that's a good suggestion, thanks @jrehwaldt. I'll give this a try and see what I can find.

  11. rnorth commented on Dec 15, 2018

    @rnorth
    Member

    Hmm, either the userns-remapping or the docker-in-docker nature of this is meaning that none of the exposed ports on any containers are accessible from Mac (not just Ryuk). I imagine this might be a limitation of Docker for Mac's TCP proxy.

    I think we'll need to do this on Linux, though, so I'll pursue that avenue.

  12. rnorth commented on Dec 15, 2018

    @rnorth
    Member

    We seem to have two issues for the same thing (this and #700), and it will get confusing having both. As such, I'll close this as the newer of the two. Please continue discussion as needed on #700.

  13. marcinar commented on Aug 12, 2026

    @marcinar

    @rnorth I don't think this was ever resolved. The problem is that Ryuk can't access the mapped domain socket unless userns remapping is turned off, and this can't be worked around without broadening the socket permissions.

    The other issue was resolved by disabling Ryuk entirely, which doesn't apply here since this isn't about CI. It would be nice if there was a simple configuration option to pass --userns=host similar the option for disabling the privileged mode.

  14. nathanburrell commented on Aug 17, 2026

    @nathanburrell

    Hey @marcinar you can disable userns-remap (amongst other advanced features such as choosing your own docker version) by using runtime v3.

    See https://support.atlassian.com/bitbucket-cloud/docs/enable-and-use-runtime-v3/

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions