Use an Alibaba Cloud Linux image in Docker

更新时间:
复制 MD 格式

Alibaba Cloud provides official Docker images for Alibaba Cloud Linux, regularly updated with the latest OS features and security patches. You can pull, run, and delete these container images on ECS instances.

Create a Docker container from an Alibaba Cloud Linux image

  1. Install and use Docker and Docker Compose.

  2. Pull an 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>
    • <image_version>: The version of Alibaba Cloud Linux, such as 2 or 3.

    • <region_ID>: The ID of the image's region, such as cn-hangzhou.

    • (Optional) <TAG>: The Docker image tag. Defaults to the latest version if omitted.

    Find image region and tag information

    1. Go to Container Registry - Artifact Center.

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

      For example, the following figure shows Alibaba Cloud Linux 3 Docker image details. ① indicates the image region, and ② indicates the image tags.

      image.png

    Sample commands:

    • Pull the 220901.1 tag of the Alibaba Cloud Linux 3 Docker image in the cn-hangzhou region.

      sudo docker pull alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1
    • Pull the latest Alibaba Cloud Linux 2 Docker image in the cn-hangzhou region.

      sudo docker pull alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2
  3. Verify the image pull.

    sudo docker images

    The output confirms that the 220901.1 Alibaba Cloud Linux 3 image and the latest Alibaba Cloud Linux 2 image were pulled.

    image.png

  4. Create and enter 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 ID of the image's region, such as cn-hangzhou.

    • (Optional) <TAG>: The Docker image tag. Defaults to the latest version if omitted.

    Sample commands:

    • Create a Docker container from the 220901.1 tag of the Alibaba Cloud Linux 3 image in the cn-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 from the latest Alibaba Cloud Linux 2 image in the cn-hangzhou region.

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

    image.png

    Note
    • Inside the container, you can run commands at the shell prompt.

    • Run exit to leave the container.

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

    The exit command stops the container. Restart and re-enter it to continue using it.

    1. Find the CONTAINER ID of the created container.

      sudo docker ps -a

      The CONTAINER ID column shows the container ID.

      image.png

    2. Start the Docker container.

      sudo docker start <CONTAINER ID>

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

      Run sudo docker ps to verify the container is running.

      image.png

    3. Enter the running Docker container.

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

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

      The output confirms you re-entered the container.

      image.png

Delete a Docker container and image

Delete unused containers and images to free resources.

  1. Stop the Docker container.

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

    sudo docker stop <CONTAINER ID>
  2. Delete the Docker container.

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

    sudo docker rm <CONTAINER ID>
  3. View all Docker containers.

    sudo docker ps -a 

    The output confirms the container is deleted.

    image

  4. Find the image's repository name.

    sudo docker images

    The REPOSITORY column shows the image name.

    image.png

  5. Delete the Docker image.

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

    sudo docker rmi <REPOSITORY>

    The output confirms the image is deleted.

    image.png

References