Docker pipeline

We have got a docker image that is working correctly. If we run without -u argument it will login as user (and not as root).

The problem is that we want the same behaviour when we use it on jenkins but the
software is always logging as root (and there is no way to change user).

This is the script:

 stage('Build image') {
        dockerImage = docker.image('ramingo92/magento-cloud:latest').inside {
            sh 'ls -la /home/user'
            sh 'whoami'

Jenkins is running on docker as container.

Any tips?

Jenkins usually runs docker images as the user that is running the job.

this probably means your jenkins [agent] is somehow root.

You can specifiy args using the inside() function. Like i said, it should default to the user of the jenkins agent, but you can override it by providing more arguments.

        dockerImage = docker.image('ramingo92/magento-cloud:latest').inside('-u 123:123') {
1 Like

Jenkins is running in a docker container (started by user1).
on jenkins we created an admin (user-jenkins) and if we set a param inside .inside(‘-u user2:user2’) the compilation got stuck. start running and does not finish.

Is there somethign wrong or some known bug?

i don’t think its a jenkins bug. My guess is the entrypoint or startup script starts up a daemon and doesn’t let jenkins do stuff.

I’m thinking guessing you want a sidecar of magento, so you might want withRun instead - Using Docker with Pipeline