0% found this document useful (0 votes)
6 views

How To Save Docker Container

Uploaded by

Mohammed Gabr
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

How To Save Docker Container

Uploaded by

Mohammed Gabr
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

To save a Docker container after installing some programs, you have a

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.

Method 1: Commit Changes to Create a New Image

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

4 This will create a new image my-image:latest from the exported


container.
Method 3: Save and Load the Entire Image

If you want to save the entire image (not just the container state) to a file:

1 Save the Image: Save the Docker image to a file:bashCopy codedocker


save -o my-image.tar my-image:latest
2
3 Load the Image Back (Optional): Load the image back into Docker:
bashCopy codedocker load -i my-image.tar

4
This will restore the saved image, which you can then use to create new
containers with your installed programs.

Choosing the Right Method

• 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!

You might also like