Back up and restore data
Estimated reading time: 2 minutes
You can use the following procedure to save and restore images and container data. For example to reset your VM disk or to move your Docker environment to a new computer.
Save your data
If you have containers that contain data that must be backed up, commit those containers to an image with
docker container commit.
Committing a container stores the container filesystem changes and some of the container’s configuration (labels, environment-variables, command/entrypoint) as a local image. Be aware that environment variables may contain sensitive information such as passwords or proxy-authentication, so care should be taken when pushing the resulting image to a registry.
Also note that filesystem changes in volume that are attached to the container are not included in the image, and must be backed up separately (see step 3 below).
Refer to the
docker container commitpage in the Docker Engine command line reference section for details on using this command.
Should I back up my containers?
If you use volumes or bind-mounts to store your container data, backing up your containers may not be needed, but make sure to remember the options that were used when creating the container or use a Docker Compose file if you want to re-create your containers with the same configuration after re-installation.
docker pushto push any images you have built locally and want to keep to the Docker Hub registry. Make sure to configure the repository’s visibility as “private” for images that should not be publicly accessible. Refer to the
docker pushpage in the Docker Engine command line reference section for details on using this command.
docker image save -o images.tar image1 [image2 ...]to save any images you want to keep to a local tar file. Refer to the
docker image savepage in the Docker Engine command line reference section for details on using this command.
Restore your data
If you backed up your images to a local tar file, use
docker image load -i images.tarto restore previously saved images.
Refer to the
docker image loadpage in the Docker Engine command line reference section for details on using this command.
- Refer to the backup, restore, or migrate data volumes page in the storage section to restore volume data.
- Re-create your containers if needed, using
docker run, or Docker Compose.