Updated on 2026-08-17 GMT+08:00

Building and Uploading an Image

This section describes how to build an entire application into a Docker image. After building an image, you can use the image to deploy and upgrade the application. This reduces manual configuration and improves efficiency.

When building an image, ensure that files used to build the image are stored in the same directory.

Required Cloud Services

SoftWare Repository for Container (SWR) provides easy, secure, reliable management over container images throughout their lifecycle, facilitating the deployment of containerized services.

Basic Concepts

  • Image: A Docker image is a special file system that includes files needed to run containers, such as programs, libraries, resources, and settings. It also includes corresponding configuration parameters, such as anonymous volumes, environment variables, and users, required within a container runtime. An image does not contain any dynamic data, and its content remains unchanged after being built.
  • Container: The relationship between an image and a container is similar to that between a class and an instance in object-oriented programming. An image provides the static definition, while a container is the running instance created from that image. A container can be created, started, stopped, deleted, or suspended.

Procedure

The following describes two methods for creating a container image. Choose one based on your requirements.

  • Creating a container image using Docker: Use the command line and a Dockerfile. A server with Docker installed is required.
  • Creating a container image using nerdctl: Use the command line and a Dockerfile. The command syntax is compatible with Docker. This method is applicable to containerd environments.

Using Docker to Create Container Images

  1. Log in as the root user to the device running Docker.
  2. Enter the apptest directory.

    cd apptest

    Ensure that all files used to build the image are stored in this directory.

  3. Build an image.

    docker build -t apptest:v1 .

  4. Upload the image to SWR. For details, see Pushing an Image.

Using nerdctl to Create Container Images

  1. Log in to the server where containerd is running and nerdctl is installed as user root.
  2. Enter the apptest directory.

    cd apptest

    Ensure that all files used to build the image are stored in this directory.

  3. Build the image.

    nerdctl build -t apptest:v1 ./

  4. Upload the image to SWR. For details, see Pushing an Image.