1

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...?

Alichino
  • 1,668
  • 2
  • 16
  • 25
  • The problem is in your bash script. Only the "/bin/bash" command is executed in your docker. The lines below aren't automatically executed inside the bin/bash you just called. – Reinout van Rees May 24 '17 at 09:49
  • I often have multiple `docker-compose run .....some command...` after each other in my Jenkinsfile. – Reinout van Rees May 24 '17 at 09:50

1 Answers1

4

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

Alichino
  • 1,668
  • 2
  • 16
  • 25