Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possibility to start Ryuk in a Network #54

Open
kanimaru opened this issue Jan 11, 2023 · 2 comments
Open

Add a possibility to start Ryuk in a Network #54

kanimaru opened this issue Jan 11, 2023 · 2 comments

Comments

@kanimaru
Copy link

Hi is it possible to start the container in a docker network?

The current problem is that, when I use Github Action and start a container it forces me into a docker network generated by Github Action and the self hosted runner in my company doesn't allow inter network communication. But Testcontainers (at least the Java lib) starts Ryuk in the default network and so it can't be reached anymore. Even when I start the docker image manually to build and test without a network it can't reach some other containers. Only when I start a new network and run the containers in it they can communicate.

Old GHA looked like that:

name: "Release Java Artifact"
on:
  workflow_dispatch:
jobs:
  build-push:
    name: Build and Push to Artifactory
    runs-on: self-hosted
    container:
      image: docker:dind # For example in our case a specialized image that contains everything to build
    steps:
      - name: Maven deploy
        run: |
          mvn -B install deploy:deploy --no-transfer-progress

My current solution is to start a network manually run the building container in it and give the network name as env variable to the container I start within the tests. But for Ryuk its currently not possible? Do you have a Idea how to solve that? I want to add the container to the deathnote 🗡️

@HofmeisterAn
Copy link
Contributor

HofmeisterAn commented Jan 11, 2023

Can you double-check which Docker host Testcontainers resolve? Considering GitHub Actions container configuration works similar to the Azure DevOps one, your container image requires a .dockerenv file in the OS root directory to resolve the right gateway. Although, I am not sure how the self-hosted runner is part of the issue. This example runs on MS-hosted agents inside a Docker container.

@kanimaru
Copy link
Author

kanimaru commented Jan 12, 2023

Sorry have no access to .dockerenv on this runner.

Some parts from the logs:

2022-12-02 13:52:31.186  INFO   --- [           main] o.t.d.DockerClientProviderStrategy       : Found Docker environment with local Unix socket (unix:///var/run/docker.sock) 
2022-12-02 13:52:31.297  INFO   --- [           main] org.testcontainers.DockerClientFactory   : Docker host IP address is 172.17.0.1 
2022-12-02 13:52:31.365  INFO   --- [           main] org.testcontainers.DockerClientFactory   : Connected to docker: 
  Server Version: 20.10.18
  API Version: 1.41
  Operating System: Ubuntu 20.04.4 LTS
  Total Memory: 16009 MB

And

2022-12-02 13:52:39.084  WARN   --- [containers-ryuk] o.t.utility.RyukResourceReaper           : Can not connect to Ryuk at 172.17.0.1:49160 
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
	at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:633)
	at org.testcontainers.utility.RyukResourceReaper.lambda$null$0(RyukResourceReaper.java:92)
	at org.rnorth.ducttape.ratelimits.RateLimiter.doWhenReady(RateLimiter.java:27)
	at org.testcontainers.utility.RyukResourceReaper.lambda$maybeStart$1(RyukResourceReaper.java:88)
	at java.base/java.lang.Thread.run(Thread.java:833)

To understand the network problems I even tried to start a local Postgres DB and tried to connect:

docker run --name postgres -p 17176:5432 -d -e POSTGRES_PASSWORD=test postgres:11-alpine
docker run -it --rm postgres:11-alpine psql -h postgres -U postgres

Same problem, no connection. Also when I specify -p 17176
Also it's not working with the Gateway IP and 17176 even when docker ps

CONTAINER ID   IMAGE                              COMMAND                  CREATED             STATUS             PORTS                                                                                            NAMES
6594cccae715   postgres:11-alpine                 "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes       0.0.0.0:17176->5432/tcp, :::17176->5432/tcp                                                      postgres

Same problem will be with Ryuk. I think the runner got hardened a bit too much.
Only connection I got was when I used directly the container IP of the postgres.

Therefore the thought was when everything runs in its own network it probably runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants