Alibaba Cloud provides official container (Docker) images based on Alibaba Cloud Linux. These images are regularly updated and maintained to include the latest OS features and security patches. Select an image version that meets your needs to build and deploy a containerized application on an Elastic Compute Service (ECS) instance. This topic describes how to pull, use, and delete Alibaba Cloud Linux container images in Docker.
Create a Docker container from an Alibaba Cloud Linux image
Run the following command to 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 as2or3.<region_ID>: The ID of the image's region, such ascn-hangzhou.(Optional)
<TAG>: The tag of the Docker image. If specified, Docker pulls the corresponding version. If omitted, Docker pulls the latest version.
Sample commands:
Pull the
220901.1tag of the Alibaba Cloud Linux 3 Docker image in thecn-hangzhouregion.sudo docker pull alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1Pull the latest Alibaba Cloud Linux 2 Docker image in the
cn-hangzhouregion.sudo docker pull alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2
Verify the image pull.
sudo docker imagesThe following sample output shows that the
220901.1tag of the Alibaba Cloud Linux 3 Docker image and the latest Alibaba Cloud Linux 2 Docker image have been successfully pulled.
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 as2or3.<region_ID>: The ID of the image's region, such ascn-hangzhou.(Optional)
<TAG>: The tag of the Docker image. If specified, Docker pulls the corresponding version. If omitted, Docker pulls the latest version.
Sample commands:
Create a Docker container from the
220901.1tag of the Alibaba Cloud Linux 3 image in thecn-hangzhouregion.sudo docker run -it alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:220901.1 /bin/bashCreate a Docker container from the latest Alibaba Cloud Linux 2 image in the
cn-hangzhouregion.sudo docker run -it alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2 /bin/bash
NoteAfter entering the container, you are at a shell prompt and can run commands.
To exit the container, run the
exitcommand.
(Optional) Restart and enter the Docker container.
Running the
exitcommand stops the container. To use it again, you must restart and re-enter it.Find the
CONTAINER IDof the created container.sudo docker ps -aIn the output,
CONTAINER IDis the container's ID.
Start the Docker container.
sudo docker start <CONTAINER ID>Replace
<CONTAINER ID>with the actual ID of your Docker container.After the container starts, you can run the
sudo docker pscommand to query running containers. In the following example, the Alibaba Cloud Linux 3 Docker container is running, confirming it started successfully.
Enter the running Docker container.
Replace
<CONTAINER ID>with the actual ID of your Docker container.sudo docker exec -it <CONTAINER ID> /bin/bashThe following output confirms you have re-entered the Alibaba Cloud Linux 3 Docker container.

Delete a Docker container and image
Delete unneeded containers and images to free up resources.
Stop the Docker container.
Replace
<CONTAINER ID>with the actual ID of your Docker container.sudo docker stop <CONTAINER ID>Delete the Docker container.
Replace
<CONTAINER ID>with the actual ID of your Docker container.sudo docker rm <CONTAINER ID>View all Docker containers.
sudo docker ps -aThe output in the following figure indicates that the container has been deleted.

Find the image's repository name.
sudo docker imagesIn the output, the
REPOSITORYcolumn shows the name of the Docker image..
Delete the Docker image.
Replace
<REPOSITORY>with the actual name of your image.sudo docker rmi <REPOSITORY>The output in the following figure confirms the Alibaba Cloud Linux 2 Docker image has been deleted.

References
For more information about how to use Docker, see Docker documentation.
For more complex deployments, you can use container orchestration tools like
docker-compose. To simplify the management and distribution of your container images, consider using Alibaba Cloud's Container Registry (ACR).
