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
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 ascn-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:
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
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.
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 ascn-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
NoteAfter 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.
(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.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.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.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.
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.
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>
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>
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.
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.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.
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.