I had an EC2 instance with "Amazon Linux 2" ami where i started a Jenkins docker container. We had a requirement to store everything in jenkins_home/ folder in s3 bucket and use the same when we bring our instance up again when we want to use it, as running instance continuously would cost us when we don't need to run it.
I started my container with the below commands.
yes | yum install docker
systemctl start docker
docker pull jenkins/jenkins:2.387.3
docker pull jenkins/jenkins
docker run -d --name my-jenkins -p 8080:8080 --restart on-failure jenkins/jenkins:2.387.3
and entered into the container using the docker exec command and copied the file from inside docker container to my EC2 instance and created a tar file from it and uploaded it in s3 bucket. Everything worked fine until now.
When I started my EC2 again and ran the jenkins/jenkins image and copied the s3 bucket tar file into EC2 instance and uploaded it in container path at "var/jenkins_home/" using the below commands.
aws s3 cp s3://dcp-jenkins-backup/jenkins.tar.gz .
tar xvzf jenkins.tar.gz
rm jenkins.tar.gz
docker cp . my-jenkins:/var/jenkins_home
I looked into the container and everything was getting copied successfully.
But when I did a docker restart the container was not getting restarted and giving me the below logs.
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
I tried changing the permissions of the files before copying into the container but that didn't work. Also tried to change permission after copying in container before docker restart but I was getting permission denied and didn't able to do it there either.
Anyway I can make this work?
I did something similar where we don't run jenkins on container either on host only. There it worked like charm.
Thanks