Jenkins - cannot create user data directory: /var/lib/jenkins/snap/docker/ : Read-only file system

2/18/2019

I am following the following doc to deploy to Kubernetes from Jenkins. I have installed jenkins in my own VM. But getting following error when build is run

+ docker build -t myregistry.azurecr.io/my-svc:latest7 ./my-svc
cannot create user data directory: /var/lib/jenkins/snap/docker/321: Read-only file system
Build step 'Execute shell' marked build as failure
Finished: FAILURE

However all the directories have jenkins use as the owner, I am not sure why it is getting into permission issues.

poc@poc-ubuntu:~$ ls -ltr     /var/lib/
drwxr-xr-x 18 jenkins       jenkins       4096 Feb 18 16:45 jenkins
-- Neil
azure
continuous-integration
docker
jenkins
kubernetes

2 Answers

2/18/2019

I believe you must be extending the Jenkins image. /var/lib/jenkins is a mount point. You can't create a directory at build time from dockerfile. If you need to create a folder in that directory then try to create using init script at container runtime

-- P Ekambaram
Source: StackOverflow

4/4/2019

Was running into the same exact issue. Here's the workaround (from user Gargoyle (g-rgoyle) here) that worked for me:

  1. Stop Jenkins: service jenkins stop
  2. Manually change Jenkins home dir: mv /var/lib/jenkins /home/jenkins
  3. Change jenkins users homedir in (might not be necessary after #2): usermod -m -d /home/jenkins jenkins
  4. Set homedir in Jenkins config: nano /etc/default/jenkins then go down to variable "JENKINS_HOME" and set value to "/home/$NAME"
  5. Start Jenkins: service jenkins start
-- Elliot Mummel
Source: StackOverflow