Skip to main content

How to set user in docker image?

Comments

3 comments

  • Gabriel Fdc

    This doesn't work, as the shell step would run outside of the docker image as it is said in https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#docker-workflow-sect-run

    So, if you have a jenkins with no nodejs, and would try to do a build inside the node docker image if you use this method:

    docker.image('node').withRun('-u node'){
    sh 'node -v'
    sh 'npm install'
    }

    you will get

    node: command not found

     

    But if you try to do it inside the docker image:

    docker.image('node').inside(){
    sh 'node -v'
    sh 'npm install'
    }

    you would get the error described in the article:

    npm ERR! Error: EACCES: permission denied, mkdir '/.npm'

    is there a way to specify the user to docker and run something inside the image?

    0
  • Denys Digtiar

    Hi Gabriel,

    Please try the following since `inside` method supports parameters in a similar way as `withRun`

    docker.image('node').inside('-u node') {
    sh 'node -v'
    sh 'npm install'
    }
    0
  • Gabriel Fdc

    Hi, thanks for replying.

    Yes after commenting i figured out i could use parameters in the inside method.

    It worked but you need to use root user, if you use node user, it will not have permissions to write in the workspace dir.

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.