Converting a mounted volume to a Docker Image

Eg:

I have a running container,with a volume mounted on it.
I want to convert the whole container along with the volume contents to a docker image.

  • Dynamic listening ports inside Docker container
  • Maintaining and supporting container base images
  • docker push fails with status 400
  • How to persist Docker data in HOST
  • Docker- connetcting AWS DynamoDB with ElasticSearch
  • Deleting images from a private docker registry
  • 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?

  • 502 Bad Gateway on Docker, NPM, PHPFPM and Symfony
  • Elasticsearch Unreachable: Connection refused
  • docker build Error checking context: 'can't stat '\\?\C:\Users\username\AppData\Local\Application Data''
  • Dockerized Spring Cloud Stream services with Kafka broker unable to connect to Zookeeper
  • Docker Rails app fails to be served - curl: (56) Recv failure: Connection reset by peer
  • How let gogs support ssh
  • 2 Solutions collect form web for “Converting a mounted volume to a Docker Image”

    Use the following steps:

    1. Use docker cp to copy the contents of the mount point to the docker host.
    2. Create a new container using the same image.
    3. Use docker cp to copy the content into the new container at desired location.
    4. 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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.