Unfortunately, this feature is not available. It has been proposed many times but not accepted by the developers. The main reason is portability; volumes are not supposed to be part of the image, and are stored outside the image.
You can still however achieve the same thing indirectly.
- Commit you container using the
docker commit
command.
- Start a new dummy container that uses the volume from the container that you are trying to backup.
docker run --volumes-from <container-name> --name backup -it ubuntu bash
- Once inside the container, tar the folder where the volume is mounted.
- Copy the volume tar from the dummy container to your host using
docker cp backup:<path-to-tar> volume.tar
Now you have multiple options:
- Create a new image using Dockerfile:
FROM commited-container-image
COPY volume.tar .
RUN tar -xf volume.tar -C path-to-volume-mount-point &&\
rm -f volume.tar
- Or untar the volume backup and mount it as a bind mount on the new container created from the container-commit image