Importing and Exporting Container Images
You can export a container as an image file and import it to other servers.
- Log in to the server as the root user.
- Run the docker ps -a command to view the container.Information similar to the following is displayed (The container is an example, the command output is subject to the actual situation.):
1 2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2ad9695f9589 ascend-toolkit:8.0.0-ubuntu18.04-arm64 "/bin/bash" 41 hours ago Up 41 hours cranky_lamport
- Run the following command to save the container as an image:
1docker commit <CONTAINER ID> <image-name:tag>
Table 1 Command parameter description Parameter
Description
CONTAINER ID
Container ID.
image-name:tag
Image name and tag, which can be customized. For example, ascend-toolkit:8.0.0-ubuntu18.04-arm64-20230109.
Example command:
1docker commit 2ad9695f9589 ascend-toolkit:8.0.0-ubuntu18.04-arm64-20230109
- Run docker images to view an image:Information similar to the following is displayed (The image is an example, the command output is subject to the actual situation.):
1 2
REPOSITORY TAG IMAGE ID CREATED SIZE ascend-toolkit 8.0.0-ubuntu18.04-arm64-20230109 c885a9197446 9 seconds ago 5.62GB
- Run the following command to save the image file:
1docker save -o <image.tar> <image-name:tag>
Table 2 Command parameter description Parameter
Description
image.tar
Name of the compressed image file, which can be customized. (Example: ascend-toolkit.tar)
image-name:tag
Image name and tag. Enter the image name and tag saved in 3, for example, ascend-toolkit:8.0.0-ubuntu18.04-arm64-20230109.
Example command:
1docker save -o ascend-toolkit.tar ascend-toolkit:8.0.0-ubuntu18.04-arm64-20230109
After the image is packed, it is generated in the current directory. You can run the ls command to view the image.
- Download the generated image file to the local host, upload the image file to any directory (for example, /home) on another server, run the docker load -i ascend-toolkit.tar command in the directory where the image is stored to import the image, and then run the docker images command to check whether the image has been imported. If the following image information is displayed, the image has been imported successfully.
1 2
REPOSITORY TAG IMAGE ID CREATED SIZE ascend-toolkit 8.0.0-ubuntu18.04-arm64-20230109 c885a9197446 About an hour ago 5.62GB
Parent topic: Common Operations for Container Deployment