All Products
Search
Document Center

Alibaba Cloud Linux:Use an Alibaba Cloud Linux image in Docker

Last Updated:Mar 25, 2024

Alibaba Cloud provides official Alibaba Cloud Linux-based Docker images that are regularly updated and maintained. The images contain the latest operating system features, functions, and security patches. You can select an Alibaba Cloud Linux image version based on your business requirements, and build and deploy containerized applications on Elastic Compute Service (ECS) instances. This topic describes how to download, use, and delete an Alibaba Cloud Linux container image in Docker.

Create a Docker instance based on an Alibaba Cloud Linux Docker image

Prerequisites

A Docker environment is deployed on an ECS instance. For more information, see Install and use Docker on a Linux instance.

Procedure

  1. Connect to an ECS instance where a Docker instance resides.

  2. Run the following command to start the Docker service:

    sudo systemctl start docker
  3. Run the following command to download the Alibaba Cloud Linux Docker image:

    sudo docker pull alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version><:TAG>

    In the preceding command, configure 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 configure this parameter, the specified Docker image version is downloaded. If you leave this parameter empty, the latest Docker image version is downloaded.

    View the region and version information of an image

    1. Log on to the Container Registry console.

    2. In the left-side navigation pane, click Artifact Center.

    3. To view the information of the Alibaba Cloud Linux 2 Docker image, click alinux2/alinux2. To view the information of the Alibaba Cloud Linux 3 Docker image, click alinux3/alinux3.

      For example, the following figure shows the information of the Alibaba Cloud Linux 3 Docker image. The ① section indicates the region in which the Docker image resides, and the ② section indicates the version information of the Docker image.

      image.png

    Sample commands:

    • Sample command used to download version 220901.1 of the Alibaba Cloud Linux 3 Docker image in the China (Hangzhou) region:

      sudo 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:

      sudo docker pull alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2
  4. Run the following command to check whether the images are downloaded:

    sudo docker images

    The command output indicates that version 220901.1 of the Alibaba Cloud Linux 3 Docker image and the latest version of the Alibaba Cloud Linux 2 Docker image are downloaded.

    image.png

  5. Run the following command to create a Docker instance and access the instance:

    sudo docker run -it alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version><:TAG> /bin/bash

    For information about the <image_version>, <region_ID>, and <:TAG> parameters, see Step 3.

    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:

      sudo docker run -it 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:

      sudo docker run -it alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2 /bin/bash

    image.png

    Note
    • After you access the container, you can use the Docker instance.

    • After the operations are complete, you can run the exit command to exit the Docker instance.

  6. (Optional) Restart and re-access the Docker instance.

    If you run the exit command to exit the instance during use, the instance is automatically stopped. If you want to continue using the instance, you must restart and re-access the instance.

    1. Run the following command to query the ID of the created Docker instance:

      sudo docker ps -a

      A command output similar to the following one is returned, where the CONTAINER ID parameter indicates the ID of the instance.

      image.png

    2. Run the following command to start the Docker instance:

      sudo docker start <CONTAINER ID>

      Replace <CONTAINER ID> with the actual Docker instance ID.

      After the Docker instance is started, you can run the sudo docker ps command to query running instances. If the Alibaba Cloud Linux 3 Docker instance is in the Running state, the instance is started. Sample command output:

      image.png

    3. Run the following command to access the started Docker instance:

      sudo docker exec -it <CONTAINER ID> /bin/bash

      Replace <CONTAINER ID> with the actual Docker instance ID.

      The following command output indicates that you re-accessed the Alibaba Cloud Linux 3 Docker instance.

      image.png

Delete a Docker instance and Docker image

If you no longer need a deployed Docker instance and image, we recommend that you delete them to reduce resource usage.

  1. Connect to an ECS instance where a Docker instance resides.

  2. Run the following command to stop the Docker instance:

    sudo docker stop <CONTAINER ID>

    Replace <CONTAINER ID> with the actual Docker instance ID.

    The following command output indicates that the Alibaba Cloud Linux 2 Docker instance is stopped.

    image.png

  3. Run the following command to delete the Docker instance:

    sudo docker rm <CONTAINER ID>

    Replace <CONTAINER ID> with the actual Docker instance ID.

    The following command output indicates that the Alibaba Cloud Linux 2 Docker instance is deleted.

    image.png

  4. Run the following command to obtain the names of Docker images:

    sudo docker images

    In the command output, the <REPOSITORY> column indicates the names of Docker images.

    image.png

  5. Run the following command to delete the Docker image used by the deleted Docker instance:

    sudo docker rmi <REPOSITORY>

    Replace <REPOSITORY> with the name of the image used by the deleted Docker instance.

    The following command output indicates that the Alibaba Cloud Linux 2 Docker image is deleted.

    image.png

References

  • You can also use container orchestration tools such as Docker Compose to manage and run Docker based on your business requirements. Alibaba Cloud also provides Container Registry to help you manage and run containerized applications.