Docker Community Forums

Share and learn in the Docker community.

Docker Compose Volume Issue

I am having problems with the volume section trying to bring up a Jenkins container in an AWS EC2 instance. I have the following docker-compose.yml file. I am able to bring up the container and all seems to work fine until I stop, remove and bring back the container. The changes I made to the instance don’t persist.

version:'2'
services:
 jenkins:
  image: jenkins
  restart: always
  ports:
   - '8080:8080'
  volumes:
   - "~/opt/jenkins:/var/lib/jenkins-home"

When I stop, remove and docker-compose up the image all changes that I made to jenkins previously are lost. Not sure what I am doing wrong.

Any help is greatly appreciated.

Got it working.

My volume section should have been:

volumes:
   - "$PWD/jenkins:/var/jenkins_home"

And we would need to give rights to jenkin user:

chown 1000 jenkins

Ref: http://stackoverflow.com/questions/34706077/starting-jenkins-in-docker-container/34709344#34709344