title: Jenkins pipeline alpine agent "apk update ERROR: Unable to lock database: Permission denied"
body: <p>I'm using Alpine docker image as a Jenkins pipeline agent but I keep getting permission denied error while running  <code>apk update</code> or <code>apk add package</code>. I seeing similar error for Ubuntu images also while running <code>apt update</code> or <code>apt install</code></p>
  
  <p>Here's my Jenkinsfile:</p>
  
  <pre class="lang-js prettyprint-override"><code>pipeline {
      agent none
      stages {
          stage('Initialization') {
              agent any
              steps {
                  checkout scm
              }
          }
  
          stage('Git Clone') {
              agent { docker { image 'alpine:3.12.0' } }
              steps {
                  sh '''
                      apk update;
                      apk add --no-cache git;
                      apk add --no-cache openssh;
                      git -v;
                  '''
              }
          }
      }
  }
  </code></pre>
  
  
  
  <p>and here's the Jenkins output:</p>
  
  <pre class="lang-js prettyprint-override"><code>+ docker inspect -f . alpine:3.12.0
  WARNING: Error loading config file: /root/.docker/config.json: stat /root/.docker/config.json: permission denied
  .
  [Pipeline] withDockerContainer
  Jenkins does not seem to be running inside a container
  $ docker run -t -d -u 1001:0 -w "/opt/bitnami/jenkins/jenkins_home/workspace/Deploy Glosfy Frontend" -v "/opt/bitnami/jenkins/jenkins_home/workspace/Deploy Glosfy Frontend:/opt/bitnami/jenkins/jenkins_home/workspace/Deploy Glosfy Frontend:rw,z" -v "/opt/bitnami/jenkins/jenkins_home/workspace/Deploy Glosfy Frontend@tmp:/opt/bitnami/jenkins/jenkins_home/workspace/Deploy Glosfy Frontend@tmp:rw,z" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** alpine:3.12.0 cat
  $ docker top 166c9ace17a4eb6aef0af0bbc04902ee4a358212be7f029550fb39a921e305aa -eo pid,comm
  [Pipeline] {
  [Pipeline] sh
  + apk update
  ERROR: Unable to lock database: Permission denied
  ERROR: Failed to open apk database: Permission denied
  [Pipeline] }
  $ docker stop --time=1 166c9ace17a4eb6aef0af0bbc04902ee4a358212be7f029550fb39a921e305aa
  $ docker rm -f 166c9ace17a4eb6aef0af0bbc04902ee4a358212be7f029550fb39a921e305aa
  [Pipeline] // withDockerContainer
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 99
  Finished: FAILURE
  </code></pre>
  
  
  
  <p>Can someone help me figure out the issue?</p>