It is possible to save a Docker container's filesystem contents to a tarball archive file. This is useful in a pinch for moving container filesystems to different hosts, for example if a database container has important changes and it isn't otherwise possible to replicate those changes elsewhere. Please note that it is preferable to create an entirely new container from an updated image using a docker run
command or docker-compose.yml
file, instead of exporting and moving a container's filesystem. Part of Docker's power is the auditability and accountability of its declarative style of creating images and containers. By using docker export
and docker import
, this power is subdued because of the obfuscation of changes made inside of a container's filesystem from its original state.
docker export -o redis.tar redis
The above command will create an empty image and then export the filesystem of the redis
container into this empty image. To import from a tarball archive, use:
docker import ./redis.tar redis-imported:3.0.7
This command will create the redis-imported:3.0.7
image, from which containers can be created. It is also possible to create changes on import, as well as set a commit message:
docker import -c="ENV DEBUG true" -m="enable debug mode" ./redis.tar redis-changed
The Dockerfile directives available for use with the -c
command line option are CMD
, ENTRYPOINT
, ENV
, EXPOSE
, ONBUILD
, USER
, VOLUME
, WORKDIR
.