Is there a way to assign network and binding ports to a docker agent in Jenkins?

Viewed 377

I have the next setup:

  • one amazon EC2 instance;
  • Jenkins installed on it;
  • Docker instance installed along with Jenkins

When I am starting the container (in a pipeline script) I am trying to add also the host network and also binding ports.

node {
    docker.image('localhost:5000/build_deploy_agent:base').withRun('-t --network host -p 9101:9101') { c ->
        sh 'doing stuff'
    }
}

I need this because at the end I want to keep the container alive with the deployed application.

The problem is, no network or ports are assigned to the container. Only the -t command is taken in consideration.

enter image description here

Is there a way to do this or I am losing time?

1 Answers
Related