.gitlab-ci.yaml use image with a specific user

Hi !

In the .gitlab-ci.yaml file, I need to use the keyword image to use a Docker image like this:
zap:

  • stage: dast*
  • image: my-docker-image*

The problem is that I don’t know how to specify the user to start the docker image with.

In local, the command that I run to use the docker image is as follows:
docker run -v $(pwd):/zap/wrk/:rw -u root -it my-docker_image

Do you know how can I indicate the user to use when starting the image?

Thanks in advance for your help.

Emy

Hi @Emy

there is no such option, the Docker image will run as the image’s default user.

There isn’t an easy way to do exactly what you want, but there are two ways to do something very similar:

  1. You could build your own Dockerfile in a preceding pipeline stage, which has the correct USER set, then push that container to the GitLab registry. Then your zap job can run with the new container which has the right user running.
  2. If you are using your own servers / runners, you could use a shell executor and just put docker run -v $(pwd):/zap/wrk/:rw -u root -it my-docker_image in your script.

It should be possible by now (even I never got it up running)