Converting a mounted volume to a Docker Image


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.

  • Boot2Docker starting Ubuntu image
  • Install Ambari based on docker on multiple hosts
  • Different env-file but same yml with Docker Compose?
  • Mounting a host directory through docker-compose file version “3” and re-using the data-volume
  • Docker for Microservice app
  • What permissions are required for docker host volume?
  • 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?

  • How can I pull a Docker image from a private Docker Hub repo remotely?
  • Why docker container can't create folders in mounted folders
  • Can't start docker service after updating to 1.12.6-176.1 in OpenSUSE:
  • Connecting to ActiveMQ Artemis Docker Container with Core API
  • Connection issue with Docker
  • How can I maximize throughput in Docker and Akka HTTP?
  • 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.