Hello everybody,
What I want to do is similar than what is done when you have a maven project and a central repository. Some dev modify a maven project, if those changes are ok then the jar artifact is published on central repository and other dev don’t have to pull the code and compile it, they just pull the final artifact from central repository.
I want to do a similar process but for a docker mysql database. Some dev pushes sql files with modifications into git repo, thoses SQL file are automatically pull on Jenkins and are executed on a docker image. If the sql file execution works fine then the modified image is pushed on our central registry. Other dev just have to pull the last docker image in order to have an up to date database.
I was able to create a Jenkins job which does the trick :
- pull last mysql image
- pull last sql files
- execute sql files on container
- commit container
- push image on registry
docker run --name MyAppMysqlContainer -e MYSQL_ROOT_PASSWORD=root -d OurRegistry/MyAppMysqlImage:latest
docker cp sqlFiles MyAppMysqlContainer:/
docker exec MyAppMysqlContainer /bin/bash -c '/update_database.sh'
docker commit --message "daily build from jenkins" MyAppMysqlContainer OurRegistry/MyAppMysqlImage:${BUILD_ID}
docker tag OurRegistry/MyAppMysqlImage:${BUILD_ID} OurRegistry/MyAppMysqlImage:latest
docker push --all-tags OurRegistry/MyAppMysqlImage
docker stop MyAppMysqlContainer
docker rm MyAppMysqlContainer
docker rmi -f $(docker images | grep 'OurRegistry/MyAppMysqlImage' | awk '{print $3}')
This job is launch everyday. My issue is that I can see that the image’s size increasing a lot each time a last version is created.
What I inspect the image history into DockerDesktop I see that an instruction is repeated each time I build :
“–datadir /var/lib/mysql-no-volume”.
I think that I don’t build the image properly, that what I have done is conceptually wrong. Do you have any hint ?