This topic describes how to download and delete an Alibaba Cloud Linux Docker image, how to use an Alibaba Cloud Linux Docker image to create a Docker instance, and how to delete a Docker instance. In the examples described in this topic, an Alibaba Cloud Linux 2 instance is used.

Prerequisites

A Docker environment is deployed. For more information, see Deploy and use Docker on Alibaba Cloud Linux 3 instances, Deploy and use Docker on Alibaba Cloud Linux 2 instances, or Deploy and use Docker on CentOS 8 instances.
Note For more information about Docker, see Docker documentation.

Download a Docker image and create a Docker instance

  1. Optional:Log on to the Container Registry console. On the Artifact Center page, obtain the tags of Alibaba Cloud Linux 2 and 3 Docker images.
    If the latest Alibaba Cloud Linux 2 and 3 Docker image versions are downloaded by default, you do not need to specify Docker image tags. In this case, skip this step.
    For example, if the latest Alibaba Cloud Linux 3 Docker image version is downloaded by default as shown in the following figure, skip this step. Image tags
  2. Connect to the ECS instance where a Docker environment is deployed.
    For more information, see Connection methods.
  3. Run the following command to download an Alibaba Cloud Linux Docker image:
    docker pull alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version>[:TAG]
    In the preceding command, set the following parameters:
    • <image_version>: the Alibaba Cloud Linux version. Example: 2 or 3.
    • <region_ID>: the region ID of the Docker image. Example: cn-hangzhou.
    • [:TAG]: optional. The tag of the Docker image. If you set this parameter, the specified Docker image version is downloaded. If you leave this parameter empty, the latest Docker image version is downloaded by default.
    Sample commands:
    • Sample command used to download version 220901.1 of the Alibaba Cloud Linux 3 Docker image in the China (Hangzhou) region:
      docker pull alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1
    • Sample command used to download the latest version of the Alibaba Cloud Linux 2 Docker image in the China (Hangzhou) region:
      docker pull alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2
    Command outputs similar to the following ones are displayed.Download an image
    After the images are downloaded, you can run the following command to view the downloaded images:
    docker images
    A command output similar to the following one is displayed.View images
  4. Run the following command to create a Docker instance:
    docker run alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version>[:TAG] /bin/bash
    In the preceding command, set the following parameters:
    • <image_version>: the Alibaba Cloud Linux version. Example: 2 or 3.
    • <region_ID>: the region ID of the Docker image. Example: cn-hangzhou.
    • [:TAG]: optional. The tag of the Docker image. If you set this parameter, the specified Docker image version is used to create a Docker instance. If you leave this parameter empty, the latest Docker image version is used to create a Docker instance.
    Sample commands:
    • Sample command used to create a Docker instance from version 220901.1 of the Alibaba Cloud Linux 3 Docker image in the China (Hangzhou) region:
      docker run alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1 /bin/bash
    • Sample command used to create a Docker instance from the latest version of the Alibaba Cloud Linux 2 Docker image in the China (Hangzhou) region:
      docker run alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2 /bin/bash
  5. Run the following command to view the ID of the created Docker instance:
    docker ps -a
    Note You can run the docker ps -a command to query created instances and the docker ps command to query running instances.
    A command output similar to the following one is displayed, where CONTAINER ID indicates the ID of the Docker instance. View the ID of the instance
  6. Run the following command to start the Docker instance.
    By default, the Docker instance enters the Stopped state after it is created. You must start the instance.
    docker start <Instance_ID>
    In the preceding command, replace <Instance_ID> with the actual Docker instance ID, which is the CONTAINER ID value.
    If the preceding command is run to start an Alibaba Cloud Linux 2 Docker instance, a command output similar to the following is displayed. Start the Docker instance
  7. Run the following command to access the started Docker instance:
    docker exec -it <Instance_ID> /bin/bash
    In the preceding command, replace <Instance_ID> with the actual Docker instance ID, which is the CONTAINER ID value.
    Note You can run the exit command to exit the Docker instance. After you exit the Docker instance, the Docker instance remains in the Running state.
    If the preceding command is run to access an Alibaba Cloud Linux 2 Docker instance, a command output similar to the following one is displayed. Access the Docker instance
    When you access the Docker instance, you can perform operations inside the instance based on your needs.

Delete a Docker instance and Docker image

You can delete Docker instances and Docker images that are no longer needed.

  1. Connect to an ECS instance where a Docker instance resides.
    For more information, see Connection methods.
  2. Run the following command to stop the Docker instance:
    docker stop <Instance_ID>
    In the preceding command, replace <Instance_ID> with the actual Docker instance ID, which is the CONTAINER ID value.
    If the preceding command is run to stop an Alibaba Cloud Linux 2 Docker instance, a command output similar to the following one is displayed. Stop the Docker instance
  3. Run the following command to delete the Docker instance.
    Before you delete the Docker instance, make sure that it is in the Stopped state. If the Docker instance is not in the Stopped state, it cannot be deleted.
    docker rm <Instance_ID>
    In the preceding command, replace <Instance_ID> with the actual Docker instance ID, which is the CONTAINER ID value.
    If the preceding command is run to delete an Alibaba Cloud Linux 2 Docker instance, a command output similar to the following one is displayed. Delete the instance
  4. Run the following command to delete the Docker image used by the deleted Docker instance.
    Before you can delete a Docker image, you must delete all instances that were created from the image.
    docker rmi <REPOSITORY_NAME>
    In the preceding command, replace <REPOSITORY_NAME> with the name of the image used by the deleted Docker instance.
    If the preceding command is run to delete an Alibaba Cloud Linux 3 Docker image, a command output similar to the following one is displayed. Delete the image