Converting a mounted volume to a Docker Image
I am tried using
docker commit container-name docker push repo/imagename:tag
but it only pushed the container, no data from volume was preserved.
Is there any way to convert data on mounted docker volume to a docker image?
2 Solutions collect form web for “Converting a mounted volume to a Docker Image”
Use the following steps:
docker cpto copy the contents of the mount point to the docker host.
- Create a new container using the same image.
docker cpto copy the content into the new container at desired location.
- Commit the new container with content in it and push it to your repository.
Another way to do this is to create a
DockerFile, then use
From directive pointing to desired base image, and use
COPY directive to copy the content to desired location (from dockerhost to image) at
docker build time.
Neither export or commit will preserve your volume data. you have 2 options though.
First: covert it to image using commit or export it then move volumes manually
Second: copy the content of your volume to any location on your container then commit it and you have now all of the data inside your image. then after transferring. Move the volume data back to its original location for ex:-
cp /my-volume-dir /my-backup-dir
then after you transfer the image
mv /my-backup-dir /my-volume-dir