I want to create a docker image, start it as a container (to configure database credentials etc.), commit those changes, tag it and push it to the container registry:
from .gitlab-ci.yml:
configure_db_image:
stage: docker_build
tags:
- docker-in-docker
script:
- docker login <gitlab-CI-CR> -u gitlab-ci-token -p $CI_JOB_TOKEN
- docker pull <gitlab-CI-CR>/db-template/db-template-image:latest
- docker tag <gitlab-CI-CR>/db-template/db-template-image:latest <gitlab-CI-CR>/my-project/my-repo/test-db-image:latest
# Remove the container if it exists already
- docker rm -f test-db-image-container || true
- docker create -i -p 5432:5432 --name test-db-image-container --env 'CREATE_ONLY_ON_FIRST_RUN=yes' --env 'DB_USER=user' --env 'DB_PASS=pass' --env 'DB_NAME=dbname' <gitlab-CI-CR>/my-project/my-repo/test-db-image:latest
- docker start -i test-db-image-container
- docker stop test-db-image-container
- docker commit test-db-image-container test-db-image
- docker tag test-db-image <gitlab-CI-CR>/my-project/my-repo/test-db-image:latest
- docker push <gitlab-CI-CR>/my-project/my-repo/test-db-image:latest
I don't see why but in spite of the docker push
the image I pull from the registry isn't configured. Where am I going wrong?
This works as described - the issue is with the Dockerfile in the parent image which declares the path where database changes happen in the file system as a Docker volume. As such they don't persist when the image is pushed to the registry.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.