The Lifecycle of an Image
Overview
SWR is a container image service that supports full lifecycle management of container images. It provides easy-to-use, secure, and reliable image management capabilities, helping you rapidly deploy containerized services. This section uses an Nginx image as an example to demonstrate how to install a container engine, build an image, and push the image to an SWR repository using a container engine client.
- Images can be pushed to SWR using a container engine client or the SWR console. This section demonstrates the client method. For details about how to push an image through the console, see Uploading an Image.
- Image push APIs are not currently available.
The following flowchart illustrates the process of using SWR.
Prerequisites
Before using SWR, complete your Huawei Cloud registration.
If you do not have a Huawei Cloud account, follow these steps to create one:
- Visit https://www.huaweicloud.com/intl/en-us/ and click Sign Up.
- Complete the registration as prompted. After successful registration, the system automatically redirects you to your personal information page.
This section uses an Nginx image as an example to describe how to write a Dockerfile based on an application, build an image, and push it to SWR. You will write a Dockerfile that uses nginx as the base image to build a new Nginx container image.
Step 1: Install a Container Engine
Prepare an ECS and install Docker on it. Ensure the engine version is 18.06 or later.
Before installing the container engine, familiarize yourself with the basics. For details, see Docker Documentation.
Purchasing and Logging In to an ECS
Buy a Linux ECS with an EIP.
For demonstration purposes, minimal specifications are sufficient. For example, an ECS with 1 vCPU and 2 GiB of memory, plus an EIP with 1 Mbit/s bandwidth, is adequate. This example uses CentOS 7.5.
- You can also install the container engine on another machine without creating an ECS.
- If you use CentOS, use CentOS 7, CentOS 7.2, CentOS 7.3, CentOS 7.4, CentOS 7.5, or CentOS 7.6. Other versions may cause installation failures.
After creation, return to the ECS list, click Remote Login in the Operation column, and log in to the ECS as user root.
Installing Docker
Run the following commands to quickly install the container engine. For details, see Docker Installation Guide.
curl -fsSL get.docker.com -o get-docker.sh sh get-docker.sh sudo systemctl daemon-reload sudo systemctl restart docker
Step 2: Build an Image
You can build an image from source code or import an image from an archive.
- Create a file named Dockerfile.
mkdir mynginx cd mynginx touch Dockerfile
- Edit the Dockerfile.
vim Dockerfile
Add the following content to the file:
FROM nginx RUN echo '<h1>Hello, SWR!</h1>' > /usr/share/nginx/html/index.html
Dockerfile instructions:
- FROM: specifies nginx as the base image. FROM is mandatory and must be the first instruction in a Dockerfile.
- RUN: executes commands during the build phase. In this example, it runs the echo command to display Hello, SWR!. The instruction is executed in the format of RUN <command>.
Press Esc, type :wq, and press Enter to save and exit.
- Run docker build [options] <context-path> to build an image.
docker build -t nginx:v1 .
- -t: specifies the image name and tag.
- .: specifies the directory containing the Dockerfile. Docker archives and transmits all content in this directory to build the image.
For more information about Dockerfiles, see Dockerfile Reference.
- Verify the image. The output shows the successfully built nginx:v1 image.
docker images
This section describes how to import an image using docker load or ctr images import.
Creating an Image Archive
This section describes how to compress a container image into a .tar or tar.gz file.
- Log in to the machine running the container engine as user root.
- Run the following command to list images:
docker images
Identify the name and tag of the image to export.
- Create the image archive.
docker save [OPTIONS] IMAGE [IMAGE...]
- OPTIONS: Set it to --output or -o to export the image to a file.
- The output file must use the .tar or .tar.gz format.
When using docker save to create an image archive, specify the image as {image}:{tag} (replace them with actual values). Do not use the image ID, as this will cause the SWR upload to fail.
Example:
docker save nginx:latest > nginx.tar ls -sh nginx.tar 108M nginx.tar docker save php:5-apache > php.tar.gz ls -sh php.tar.gz 372M php.tar.gz docker save --output nginx.tar nginx ls -sh nginx.tar 108M nginx.tar docker save -o nginx-all.tar nginx # Archive all tags of the nginx image. docker save -o nginx-latest.tar nginx:latest
Importing the Image File
docker load < path/filename.tar docker load --input path/filename.tar or docker load --i path/filename.tar
docker load --input fedora.tar
Step 3: Create an Organization
Organizations isolate images and allow you to assign different permissions (read, edit, manage) to IAM users under your account.
- Log in to the SWR console.
- Click
in the upper left corner to select the target region and project. - Choose Organizations in the navigation pane.
- Click Create Organization in the upper right corner of the page. In the displayed dialog box, enter a name and click OK.

Table 1 Parameters for creating an organization Parameter
Example Value
Description
Organization Name
cloud-develop
Organizations are used to isolate image repositories. Each organization is typically scoped to one company or department, enabling centralized and efficient image management.
Enter 1 to 64 characters, starting with a lowercase letter and ending with a lowercase letter or digit. Only lowercase letters, digits, periods (.), underscores (_), and hyphens (-) are allowed. Periods, underscores, and hyphens cannot be adjacent to each other. A maximum of two consecutive underscores are allowed. Multiple consecutive hyphens are allowed.
- The organization name must be unique in the current region. If a message is displayed indicating that the organization already exists, the organization name may have been used by another user. Use another organization name.
- A user can create organizations only after being assigned the SWR Admin or Tenant Administrator policy in IAM.
- The organization name cannot be library, which is reserved for the system.
Step 4: Access SWR
- SWR console.
- In the navigation pane, choose Dashboard. Click Generate Login Command in the upper right corner. Then, click
to copy the login command. Figure 2 Login Command
You can specify the validity period of a temporary login command, from 15 minutes to 24 hours. For long-term access, see Obtaining a Long-Term Login or Image Push/Pull Command.
Docker clients require a login command; containerd clients do not.
- Run the copied login command on the ECS where the container engine is installed.
Upon successful login, Login Succeeded is displayed.
Step 5: Push the Image
This section describes how to push an image using a Docker client.
- On the ECS where the container engine is installed, run the following command to tag the nginx image:
docker tag [image-name-1:tag 1] [image-repository-address]/[organization-name]/[image-name-2:tag-2]
where,
- [image-name-1:tag-1]: Replace it with the name and tag your image to push.
- [image-repository-address]: the domain name from the login command in Step 4: Access SWR. You can retrieve this address from the SWR console.
- [organization name]: the name of the organization created in Step 3: Create an Organization.
- [image-name-2:tag-2]: the target image name and tag.
Example:
docker tag nginx:v1 swr.ap-southeast-1.myhuaweicloud.com/cloud-develop/nginx:v1
- Push the image to SWR.
docker push [image-repository-address]/[organization-name]/[image-name-2:tag-2]
Example:
docker push swr.ap-southeast-1.myhuaweicloud.com/cloud-develop/nginx:v1
The following output is returned upon a successful push:
The push refers to repository [swr.ap-southeast-1.myhuaweicloud.com/cloud-develop/nginx] fbce26647e70: Pushed fb04ab8effa8: Pushed 8f736d52032f: Pushed 009f1d338b57: Pushed 678bbd796838: Pushed d1279c519351: Pushed f68ef921efae: Pushed v1: digest: sha256:0cdfc7910db531bfa7726de4c19ec556bc9190aad9bd3de93787e8bce3385f8d size: 1780
To view the pushed image, return to the SWR console and refresh the My Images page.
Step 6: Pull the Image
Pulling (downloading) an image retrieves it from the repository for local use. This is commonly used with Huawei Cloud CCE for workload deployment or CCI for instance deployment.
- Log in to the SWR console.
- In the navigation pane, choose My Images.
- Click the image name to go to the image details page.
- Click the Pull/Push tab, select Docker Guide, copy the generated docker pull command, and run the command on the terminal. Example:
docker pull swr.cn-east-3.myhuaweicloud.com/group/nginx:v2.0.0
- View the pulled image.
docker images
Step 7: Delete the Image
SWR supports full lifecycle management of container images, including push, pull, and deletion.
- Log in to the SWR console.
- In the navigation pane, choose My Images.
- Locate the target image, click More in the Operation column, and choose Delete from the drop-down list.
- In the confirmation dialog box, enter DELETE and click OK.
# List local images. docker images # Delete a local image. docker rmi [image-name:tag]
docker rmi swr.cn-north-4.myhuaweicloud.com/cloud-develop/nginx:v1
docker rmi nginx:v1
Before deleting an image, ensure no container is using it. Run docker ps -a to list all containers. Then, stop or remove any containers using the image.
The docker rmi command deletes only local images, not images in the SWR repository. To delete repository images, use the console method above.
Step 8: Delete the Organization
- Log in to the SWR console.
- Click
in the upper left corner to select the target region and project. - In the navigation pane, choose Organizations.
- Locate the target organization and click Delete in the upper right corner of the organization. Then, click OK. Figure 3 Deleting an organization

What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot