Reinis
Reinis

Reputation: 136

Docker commit doesn't make changes to containers union file system

This probably has been asked at some point, but I can't find it anywhere. I can't seem to be able (or can't figure out how) to commit changes to a docker image without losing file changes in the container that i'm committing. Here's my use case. I use Boot2Docker on Windows,

Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8

I pull the newest version of jenkins from dockerHub.

docker pull jenkins

I run it, rerouting it's web interface port

docker run -dt -p 8010:8080 jenkins

I go to the interface to install some plugins. I install the plugins and then restart Jenkins. I then try to commit my changes.

docker commit $(docker ps -lq) <my_user_name_on_docker_hub>/<name_of_the_new_image>

docker ps -lq returns the id of the last running container. Since i'm running only this container at this moment, i'm sure that this returns the correct id (i also checked it by doing docker ps and actually looking up the container) Then I push the changes.

docker push <my_user_name_on_docker_hub>/<name_of_the_new_image>

The push goes through all of the revisions that already exist on the dockerHub and skips them all until it hits the last one and uploads four megabytes to the registry. And yet, when i try to run this new image, it's just the base image of jenkins without any changes. Without the plugins that i installed. As far as i understand, the changes to the union file system of the image (jenkins plugins are installed as binaries there) should be commited. I need to have a new image with my changes on it.

What am I doing wrong?

EDIT: i created a couple of test jobs, ran them, walked around the file system using docker exec -it bash, and jenkins creates a new directory for each job under /var/jenkins_home/jobs, but when i do docker diff, it shows that only temp files have been created. And after committing, pushing, stopping the container and running a new one from the image that just got pushed, the job folders disappear together with everything else.

EDIT2: i tried creating files in other folders and docker diff seems to be seeing the changes everywhere else except for /var/jenkins_home/ directory.

EDIT3: this seems to be related -- from Jenkins DockerHub page

How to use this image

docker run -p 8080:8080 jenkins This will store the workspace in /var/jenkins_home. All Jenkins data lives in there - including plugins and configuration. You will probably want to make that a persistent volume:

docker run --name myjenkins -p 8080:8080 -v /var/jenkins_home jenkins The volume for the “myjenkins” named container will then be persistent.

You can also bind mount in a volume from the host:

First, ensure that /your/home is accessible by the jenkins user in container (jenkins user - uid 102 normally - or use -u root), then:

docker run -p 8080:8080 -v /your/home:/var/jenkins_home jenkins

I tried running the command with the -v toggle, but that didn't really make my commit any more persistent.

Upvotes: 2

Views: 1058

Answers (1)

Reinis
Reinis

Reputation: 136

It was my fault for not looking at the docs for the Jenkins docker image

How to use this image

docker run -p 8080:8080 jenkins This will store the workspace in /var/jenkins_home. All Jenkins data lives in there - including plugins and configuration. You will probably want to make that a persistent volume:

docker run --name myjenkins -p 8080:8080 -v /var/jenkins_home jenkins The volume for the “myjenkins” named container will then be persistent.

https://registry.hub.docker.com/_/jenkins/

Upvotes: 1

Related Questions