Search code examples
dockerjenkinsjenkins-pipelinejenkins-docker

Jenkins docker - running a container, executing shell script etc


I'm trying to run docker containers in the Jenkins Pipeline.

I have the following in my Jenkinsfile:

stage('test') {
 steps {
  script {
    parallel (
        "gatling" : {
            sh 'bash ./test-gatling.sh'
    }, 
        "python" : {
            sh 'bash ./test-python.sh'
    })
               }
         }
       }

In the test-gatling.sh I have this:

#!/bin/bash
docker cp RecordedSimulation.scala denvazh/gatling:/RecordedSimulation.scala
docker run -it -m denvazh/gatling /bin/bash
ls
./gatling.sh

The ls command is there just for test, but when it's executed it lists files and folders of my github repository, rather than the files inside the denvazh/gatling container. Why is that? I thought the docker run -it [...] command would open the container so that commands could be run inside it?

================

Also, how do I run a container and just have it running, without executing any commands inside it? (In the Jenkins Pipeline ofc)

I'd like to run: docker run -d -p 8080:8080 -t [my_container] and access it on port 8080. How do I do that...?


Solution

  • If anyone has the same or similar problem, here are the answers:

    1. Use docker exec [name of container] command, and to run any terminal commands inside a container, add /bin/bash -c "[command]"

    2. To be able to access a container/app that is running on any port from a second container, when starting the second container run it with --net=host parameter