Skip to content

[Bug]: Can't connect to Ryuk when running in container on Jenkins (Windows) #9907

@Rapter1990

Description

@Rapter1990

Module

MongoDB

Testcontainers version

1.20.4

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host Arch

Windows x64

Docker version

Client:
 Cloud integration: v1.0.29 
 Version:           20.10.21
 API version:       1.41    
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:08:16 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.14.1 (91661)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:00:19 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I want to run all tests written in JUnit and Integration tests through Jenkins as CI/CD process in my Spring boot.

I created grrovy file, dockerfile and docker compose yml for Jenkins.

Here is the groovy file show below

import hudson.plugins.git.UserRemoteConfig
import hudson.plugins.git.BranchSpec
import hudson.plugins.git.GitSCM
import jenkins.model.*
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition

def instance = Jenkins.getInstance()

def jobName = "flightsearchapi"
def job = instance.getItem(jobName)

if (job != null) {
    job.delete()
}

def pipelineJob = instance.createProject(org.jenkinsci.plugins.workflow.job.WorkflowJob, jobName)
def definition = new CpsScmFlowDefinition(
        new GitSCM(
                [
                        new UserRemoteConfig("https://github.com/Rapter1990/flightsearchapi.git", null, null, null)
                ],
                [new BranchSpec("*/development/issue-2/implement-jenkins-for-ci-cd")],
                false, Collections.emptyList(),
                null, null, Collections.emptyList()
        ),
        "Jenkinsfile"
)
definition.setLightweight(true)
pipelineJob.setDefinition(definition)
pipelineJob.save()

println("Pipeline job '${jobName}' has been successfully created!")

Here is the dockerfile shown below

FROM jenkins/jenkins:lts

# Plugin list
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt

# For Groovy scripts, init.d directory
COPY init.groovy.d/ /var/jenkins_home/init.groovy.d/

# Install Docker CLI
USER root
RUN apt-get update && apt-get install -y docker.io

Here is the docker-compose yml file

version: '3.9'

services:
  jenkins:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: jenkins-server
    ports:
      - "8080:8080"    # Expose Jenkins UI on port 8080
      - "50000:50000"  # Expose port for Jenkins agents
    volumes:
      - jenkins_home:/var/jenkins_home   # Persistent Jenkins data
      - /var/run/docker.sock:/var/run/docker.sock # Mount Docker socket for Docker builds
      - ../k8s:/var/jenkins_home/k8s # Mount Kubernetes configuration files (optional)
      - ./init.groovy.d:/var/jenkins_home/init.groovy.d # Mount Jenkins init scripts (optional)
    environment:
      JAVA_OPTS: "-Djenkins.install.runSetupWizard=false" # Skip setup wizard (optional)
    user: root # Run as root to allow installing dependencies

volumes:
  jenkins_home:

When I run docker-compose through docker-compose up -d and run pipeline , I got the error shown below

It works with Linux but it couldn't work on Windows.

How can I fix the issue?

Relevant log output

12:47:17.631 [main] INFO org.testcontainers.DockerClientFactory -- Docker host IP address is 172.17.0.1
    12:47:17.679 [main] INFO org.testcontainers.DockerClientFactory -- Connected to docker: 
      Server Version: 20.10.21
      API Version: 1.41
      Operating System: Docker Desktop
      Total Memory: 12678 MB
    12:47:17.790 [main] INFO tc.testcontainers/ryuk:0.11.0 -- Creating container for image: testcontainers/ryuk:0.11.0
    12:47:17.814 [main] INFO org.testcontainers.utility.RegistryAuthLocator -- Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: testcontainers/ryuk:0.11.0, configFile: /root/.docker/config.json, configEnv: DOCKER_AUTH_CONFIG). Falling back to docker-java default behaviour. Exception message: Status 404: No config supplied. Checked in order: /root/.docker/config.json (file not found), DOCKER_AUTH_CONFIG (not set)
    12:47:18.097 [main] INFO tc.testcontainers/ryuk:0.11.0 -- Container testcontainers/ryuk:0.11.0 is starting: a821037942a489255c5ee014be369aecbeb7793ff5b60a9b7189497e103051cd
    12:47:18.906 [main] INFO tc.testcontainers/ryuk:0.11.0 -- Container testcontainers/ryuk:0.11.0 started in PT1.1156687S
    12:47:18.917 [testcontainers-ryuk] WARN org.testcontainers.utility.RyukResourceReaper -- Can not connect to Ryuk at 172.17.0.1:30511
    java.net.ConnectException: Connection refused

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions