Docker Tips — Export Container to Image
If you want to create an image from a Docker container that contains edits to the original image, but don’t want to have to commit it to a public repository you can take the following steps.
- First find the name of your docker container.
# If the container is still active
docker container list
# Else if the container is no longer active
docker container list --all
2. Using the name of the container (e.g. personal_panda), run the docker export command to export the container to a file.
# If you don't care about disk space.
docker export personal_panda > export_file.tar
# If you want to compress it.
docker export personal_panda | gzip > export_file.tar.gz
3. Convert the file to a docker image.
# From an uncompressed tarball.
cat export_file.tar | docker import - exported_image
# From a compressed tarball.
gzcat export_file.tar.gz | docker import - exported_image
You can now start the exported image and continue doing whatever you were doing.
Note: You will lose the image history of the container. I’ve done this mostly to debug long running docker scripts (e.g. installing a lot of system dependencies).
Other ways and more detail can be found here: