0

I have Jenkins installed in Docker container by the following guideline https://www.jenkins.io/doc/book/installing/docker/

I am also trying to install Selenoid image in Jenkins using the pipeline

pipeline {
    agent any

    stages {
        stage('Prepare Selenoid') {
            steps {
                sh 'wget "https://github.com/aerokube/cm/releases/download/1.8.2/cm_linux_amd64"'
                sh 'chmod +x cm_linux_amd64'
                sh './cm_linux_amd64 selenoid start –vnc'
                sh 'docker ps'
                sh 'docker logs selenoid'
                sh 'curl http://localhost:4444/status'
            }
        }
    }
    
    post {
        always { 
            script {
                sh 'docker stop selenoid'
                sh 'docker rm selenoid'
            }
        }
    }
}

When I run this job, I got the following logs:

...
> Starting Selenoid...
> Successfully started Selenoid
+ docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED         STATUS                  PORTS                    NAMES
99467c57d5c6   aerokube/selenoid:1.10.9   "/usr/bin/selenoid -…"   2 seconds ago   Up Less than a second   0.0.0.0:4444->4444/tcp   selenoid
+ docker logs selenoid
2023/01/13 17:09:45 [-] [INIT] [Loading configuration files...]
2023/01/13 17:09:45 [-] [INIT] [Loaded configuration from /etc/selenoid/browsers.json]
2023/01/13 17:09:45 [-] [INIT] [Video Dir: /opt/selenoid/video]
2023/01/13 17:09:45 [-] [INIT] [Logs Dir: /opt/selenoid/logs]
2023/01/13 17:09:45 [-] [INIT] [Using Docker API version: 1.41]
2023/01/13 17:09:45 [-] [INIT] [Timezone: UTC]
2023/01/13 17:09:45 [-] [INIT] [Listening on :4444]
+ curl http://localhost:4444/status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to localhost port 4444: Connection refused
script returned exit code 7+ 
...

I also tried different options: 0.0.0.0:4444/status 127.0.0.1:4444/status

Sundel
  • 1
  • 1
  • You seem to have set up Selenoid correctly, so this is a different issue. Exec into the Jenkins container and curl localhost:4444. If that works, then it is a problem with running curl on Jenkins. If it doesn't, then it is not a problem with Jenkins but the Selenoid image itself. – M B Jan 14 '23 at 04:25
  • curl localhost:4444 still returns the same error. Actually, just for testing purposes I tried curl www.google.com and then it worked. I think maybe issue is with localhost, but have no idea what it should be then – Sundel Jan 14 '23 at 09:38
  • I would try http://127.0.0.1:4444 – damiensprinkle Feb 16 '23 at 23:00

1 Answers1

0

Your pipeline code is probably also running in another container. So localhost inside this container is not the localhost of the host machine you are expecting to access. Try to use http://selenoid:4444/, but make sure your container is running in selenoid network being used by CM tool by default.

vania-pooh
  • 2,933
  • 4
  • 24
  • 42
  • Hi, thank you for your answer. I tried both: curl http://selenoid:4444/status curl http://jenkins:4444/status (because I used jenkins as a network name when running docker) both is not working: could not resolve host: selenoid. I tried to check the network with: docker inspect selenoid -f "{{json .NetworkSettings.Networks }}". Thats what is says: { "selenoid": { "IPAMConfig": null, "Links": null, "Aliases": [ "010a1c2c7851", "localhost" ], ... } } – Sundel Jan 14 '23 at 18:52
  • You have to use container name and not network name. – vania-pooh Jan 19 '23 at 08:26