1

Situation

My CI pipeline needs to do the following:

  • log into a VM and have access to a bash terminal
  • run a bash script that launches a Docker container with parameters (e.g. -it mode or providing the IP address of the machine that the tests will attack)
  • from within that Docker container, launch a series of tests.

The Docker container is built in such a way that it maps the current directory of the VM from which I'm doing the docker run, and then it navigates to the tests folder and launches them.

What I currently have

I created a GitLab runner in shell mode. I'm able to launch the container throughout the script but as soon as it succeeded, it exits the container and therefore I can't run my tests.

Constraints

I don't have the Dockerfile of this docker image, only the container. I can't edit the file to provide the parameters in it.

How could I run that docker container without having it to stop? I figured two ways of doing it but I didn't manage to make either of them work:

  1. Configure the runner to work with these input parameters → so far I didn't figure how to do this. In the gitlab-runner register all I seem to be able to do is to specify that this is a Docker container, I can't provide parameters on how to run the container.

  2. Prevent the line from exiting after having run the container successfully. This is a bash issue that I have been trying to fix but I can't seem to figure out how to do this.

For what it's worth here is the content of the bash script I'm using to launch the container:

SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )


IMAGE="path/to/docker/image"

if [[ -z "$@" ]]; then
        docker run --rm -it -u username -v $SCRIPT_DIR/../..:/project $IMAGE
else
        for arg; do HOSTS+="--add-host=$arg "; done
        docker run --rm -it -u username -v $SCRIPT_DIR/../..:/project $HOSTS $IMAGE
fi

And I call it like this:

./launch-docker-container.sh parameter:param_to_bind

How could I launch a docker container from within a GitLab Shell runner?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.