How To Save Docker Container
How To Save Docker Container
couple of options depending on what you want to achieve. You can either
commit the changes to create a new image based on the modified
container, or you can export the container as a .tar file for backup or
sharing.
1 Start the Container: Start a container and make changes (e.g., install
programs):bashCopy codedocker run -it --name my-container
ubuntu:latest /bin/bash
2 After the container is running, install your desired programs and make any
changes you want.
3 Commit the Container: Once you are done making changes inside the
container, you can commit the container to a new image: bashCopy code
docker commit my-container my-image:latest
4 This will create a new image my-image:latest based on the state of my-
container.
5 Run the New Image: You can now use the newly created image to start
containers with your saved changes:bashCopy codedocker run -it my-
image:latest /bin/bash
6
Method 2: Save the Container as a .tar File
If you want to save the container's state as a file (e.g., for backup or
sharing):
1 Export the Container: You can export the container to a .tar file:bash
Copy codedocker export my-container -o my-container.tar
2 This command will save the entire file system of the container into my-
container.tar.
3 Import the Container Back (Optional): If you want to restore or use
the saved .tar file later, you can import it as an image:bashCopy code
docker import my-container.tar my-image:latest
If you want to save the entire image (not just the container state) to a file:
4
This will restore the saved image, which you can then use to create new
containers with your installed programs.
• Use docker commit when you want to create a new image with the
changes you made inside the container.
• Use docker export if you want to create a backup of a container's state
or share it without needing to commit it as an image.
• Use docker save and docker load when you want to save and
transfer images (not container states) between systems.
Let me know if you need any further assistance with these steps!