All Products
Search
Document Center

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

Last Updated:Apr 16, 2025

Alibaba Cloud provides official Docker images based on Alibaba Cloud Linux and regularly updates and maintains them to ensure they contain the latest operating system attributes, features, and security patches. You can select an appropriate Alibaba Cloud Linux image version based on your requirements and build and deploy containerized applications on ECS instances. This topic describes how to download, use, and delete Alibaba Cloud Linux Docker images.

Create a Docker container based on an Alibaba Cloud Linux image

  1. Install Docker.

  2. Run the following command to download a Docker image of Alibaba Cloud Linux.

    sudo docker pull alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version>:<TAG>
    • <image_version>: The version of Alibaba Cloud Linux, such as 2 or 3.

    • <region_ID>: The region where the Docker image is located, such as cn-hangzhou.

    • (Optional) <TAG>: The version 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.

    How do I view the region where the image is located and the image version information?

    1. Visit Container Registry - Artifact Center.

    2. Click alinux2/alinux2 or alinux3/alinux3 to view the Docker image version information of Alibaba Cloud Linux 2 and Alibaba Cloud Linux 3.

      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
  3. Run the following command to check whether the image is 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

  4. Run the following command to create and access a Docker container.

    sudo docker run -it alibaba-cloud-linux-<image_version>-registry.<region_ID>.cr.aliyuncs.com/alinux<image_version>/alinux<image_version>:<TAG> /bin/bash
    • <image_version>: The version of Alibaba Cloud Linux, such as 2 or 3.

    • <region_ID>: The region where the Docker image is located, such as cn-hangzhou.

    • (Optional) <TAG>: The version 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:

    • Create a Docker container based on 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
    • Create a Docker container based on 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 directly use the Docker container.

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

  5. (Optional) Restart and access the Docker container.

    When you use a Docker container, if you run the exit command to exit the container, the container automatically stops. If you need to continue using the container, you must restart and access the container.

    1. Run the following command to query the ID of the created Docker container to start the container.

      sudo docker ps -a

      The query result is displayed as follows. CONTAINER ID indicates the container ID.

      image.png

    2. Run the following command to start the Docker container.

      sudo docker start <CONTAINER ID>

      Replace <CONTAINER ID> with the actual ID of your Docker container.

      After the container is started, you can run the sudo docker ps command to query the running container. In the following example, the Alibaba Cloud Linux 3 Docker container is running, which indicates that the container is started.

      image.png

    3. Run the following command to access the started Docker container.

      Replace <CONTAINER ID> with the actual ID of your Docker container.

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

      The following figure shows that the Alibaba Cloud Linux 3 Docker container is accessed again.

      image.png

Delete Docker containers and Docker images

When you no longer need the deployed Docker containers and images, we recommend that you delete them to reduce resource usage.

  1. Run the following command to stop the Docker container.

    Replace <CONTAINER ID> with the actual ID of your Docker container.

    sudo docker stop <CONTAINER ID>
  2. Run the following command to delete the Docker container.

    Replace <CONTAINER ID> with the actual ID of your Docker container.

    sudo docker rm <CONTAINER ID>
  3. Run the following command to view Docker containers.

    sudo docker ps -a 

    The result shown in the following figure indicates that the Docker container is deleted.

    image

  4. Run the following command to obtain the image name.

    sudo docker images

    As shown in the following figure, the <REPOSITORY> column indicates the Docker image name.

    image.png

  5. Run the following command to delete the Docker image.

    Replace <REPOSITORY> with the actual name of your image.

    sudo docker rmi <REPOSITORY>

    The result shown in the following figure indicates that the Alibaba Cloud Linux 2 Docker image is deleted.

    image.png

References

  • For more information about how to use Docker, see Docker documentation.

  • 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, which helps you manage and run containerized applications more easily.