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
Connect to an ECS instance where a Docker instance resides.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to start the Docker service:
sudo systemctl start docker
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.
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 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.
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
NoteAfter 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.
(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.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.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: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.
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.
Connect to an ECS instance where a Docker instance resides.
For more information, see Connect to a Linux instance by using a password or key.
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.
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.
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.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.
References
For 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 to help you manage and run containerized applications.