tencent cloud

Building the Docker
Last updated: 2025-06-19 16:14:08
Building the Docker
Last updated: 2025-06-19 16:14:08

Overview

This document describes how to build and use Docker in CVM. It is intended for new CVM users who are familiar with the Linux operating system. To learn more about Docker, see Docker's official.
Note:
The Windows Subsystem for Linux (WSL) encounters some limitations in Windows Server 2022. Due to system kernel integrity, WSL 1 cannot run Linux Docker. WSL 2 can run Linux Docker, but it requires hardware support for nested virtualization, which is not supported on standard cloud servers (including Lighthouse). Therefore, neither WSL 1 nor WSL 2 can run Linux Docker on standard Windows cloud servers.
For a standard Windows cloud server (including Lighthouse), installing Docker Desktop on Windows is not supported; for a Windows bare metal physical server, Windows Server 2022 is recommended. For specific information, see the related document Microsoft Official Documentation - Preparing Windows for Containers to perform configuration.

About OS Versions

This document takes Tencent Cloud public images of TencentOS Server 4, TencentOS Server 3, CentOS 8.2, CentOS 7.9, Ubuntu 22.04, Debian 12.5, OpenCloudOS 9.0, and OpenCloudOS 8.0 as examples for CVM instance operating systems.
If you use TencentOS Server 2.4 (TK4), Docker is pre-installed in the image and does not need to be installed again. See Using Docker for quick start.

Prerequisites

You have purchased a Linux CVM.
Note:
Docker must be built on a 64-bit operating system with the kernel version 3.10 or later.

Directions

Installing Docker

Perform the following directions based on your operating system version:
2. Installing Docker.
TencentOS Server 4
TencentOS Server 3
CentOS 8.2
CentOS 7.9
Ubuntu 22.04
Debian 12.5
OpenCloudOS 9.0
OpenCloudOS 8.0
1. The public image of this operating system version has a pre-installed Docker repository of Tencent Cloud. You can execute the following command to install Docker.
sudo yum install docker -y
2. Execute the following command to run Docker.
sudo systemctl start docker
3. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.



1. The public image of this operating system version has a pre-installed docker-ce repository of Tencent Cloud. You can execute the following command to install Docker.
sudo dnf install -y docker-ce --nobest
2. Execute the following command to run Docker.
sudo systemctl start docker
3. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.



1. Execute the following command, add the Docker software repository, and configure it as the repository of Tencent Cloud.
sudo dnf config-manager --add-repo=https://mirrors.cloud.tencent.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i "s/download.docker.com/mirrors.tencentyun.com\\/docker-ce/g" /etc/yum.repos.d/docker-ce.repo
2. Execute the following command to view the added Docker software repository.
sudo dnf list docker-ce
3. Execute the following command to install Docker.
sudo dnf install -y docker-ce --nobest
4. Execute the following command to run Docker.
sudo systemctl start docker
5. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.




1. Execute the following command, add the Docker software repository, and configure it as the repository of Tencent Cloud.
sudo yum-config-manager --add-repo=https://mirrors.cloud.tencent.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i "s/download.docker.com/mirrors.tencentyun.com\\/docker-ce/g" /etc/yum.repos.d/docker-ce.repo
2. Execute the following command to view the added Docker software repository.
sudo yum list docker-ce
3. Execute the following command to install Docker.
sudo yum install -y docker-ce
4. Execute the following command to run Docker.
sudo systemctl start docker
5. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.


1. Execute the following command to add the Docker software repository.
sudo apt-get update
sudo apt-get install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu/ \\
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
2. Execute the following command to install Docker.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Execute the following command to run Docker.
sudo systemctl start docker
4. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.


1. Execute the following command to add the Docker software repository.
sudo apt-get update
sudo apt-get install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://mirrors.cloud.tencent.com/docker-ce/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.cloud.tencent.com/docker-ce/linux/debian/ \\
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
2. Execute the following command to install Docker.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Execute the following command to run Docker.
sudo systemctl start docker
4. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.


1. Execute the following command to install Docker.
sudo yum install docker -y
2. Execute the following command to run Docker.
sudo systemctl start docker
3. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.



1. Execute the following command, add the Docker software repository, and configure it as the repository of Tencent Cloud.
sudo dnf config-manager --add-repo=https://mirrors.cloud.tencent.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i "s/download.docker.com/mirrors.tencentyun.com\\/docker-ce/g" /etc/yum.repos.d/docker-ce.repo
2. Execute the following command to view the added Docker software repository.
sudo dnf list docker-ce
3. Execute the following command to install Docker.
sudo dnf install -y docker-ce --nobest
4. Execute the following command to run Docker.
sudo systemctl start docker
5. Execute the following command to check the installation result.
sudo docker info
If the following message is returned, it indicates the installation is successful.




Using Docker

You can use Docker with the following commands:
Manage the Docker daemon.
Run the Docker daemon.
sudo systemctl start docker
Stop the Docker daemon.
sudo systemctl stop docker
Restart the Docker daemon.
sudo systemctl restart docker
Manage images. This document uses the Nginx image of Docker Hub as an example.
sudo docker pull nginx
Note:
If the docker pull command returns an error: "Get "https://registry-1.docker.io/v2/": xxxxx (Client.Timeout exceeded while awaiting headers)", it indicates a network issue. It is recommended to see Accelerating Docker using the Tencent Cloud image source to change the repository.
Modify image tag to help you identify the image.
sudo docker tag docker.io/nginx:latest tencentyun/nginx:v1
Query existing images.
sudo docker images
Forcibly delete an image.
sudo docker rmi -f tencentyun/nginx:v1
Manage containers.
Run and enter a container.
sudo docker run -it ImageId /bin/bash
The ImageId can be obtained by executing the docker images command. To run the entered container in the backend, you can directly exit the current SSH connection window or press Ctrl+p followed by Ctrl+q.
Run a new bash process in containers running in the backend.
docker exec -it container ID /bin/bash
Exit the bash process by executing the exit command.
View backend containers:
sudo docker ps # View running containers.
sudo docker ps -a # View all containers.
Restart exited containers.
docker start <container ID>
Exited containers can be queried using the sudo docker ps -a command. Those whose STATUS column output by the command contains "Exited" are the exited containers.
Create an image from the container.
sudo docker commit <container ID or container name> [<repository name>[:<tag>]]
For example:
sudo docker commit 1c23456cd7**** tencentyun/nginx:v2

Creating images

1. Run the following command to open the “Dockerfile” file.
vim Dockerfile
2. Press i to switch to the edit mode and enter the following:
#Declare a basic image.
FROM tencentyun/nginx:v2
#Declare the image owner.
MAINTAINER DTSTACK
#Add the command that needs to be run before the container starts after the RUN command. Since Dockerfile files can only contain a maximum of 127 lines, we recommend that you write and run the commands in the script.
RUN mkdir /dtstact
RUN apt update && apt install -y iputils-ping
#The commands that run at startup. The last command must be a frontend command that runs constantly. Otherwise, the container will exit after running all commands.
ENTRYPOINT ping cloud.tencent.com
3. Click Esc and enter :wq to save and close the file.
4. Run the following command to build an image.
sudo docker build -t nginxos:v1 . #The single dot (.) specifies the path of the Dockerfile and must be included.
5. Run the following command to check if the image has been created.
sudo docker images
6. Run the following commands in sequence to run and check the container.
sudo docker run -d nginxos:v1 #Run the container in the background.
sudo docker ps #Check the running container.
sudo docker ps -a #Check all containers including those that are not running.
sudo docker logs CONTAINER ID/IMAGE #Check the startup log to troubleshoot the issue based on the container ID or name if you do not see the container in the returned results
7. Run the following commands in sequence to create an image.
sudo docker commit fb2844b6**** nginxweb:v2 #Add the container ID and the name and version of the new image. after the commit command.
sudo docker images #List local images that have been downloaded and created.
8. Run the following command to push the image to the remote repository. The image is pushed to Docker Hub by default. To push the image, log in to Docker, tag and name the image in the following format: Docker username/image name: tag.
Note:
The execution is successful when the server can normally access https://registry-1.docker.io. Otherwise, a timeout error will be reported.
The solution for timeout error is pushing to another accessible warehouse, such as pushing to Tencent Cloud TCR.
sudo docker login #Enter the username and password of the image registry after running the command
sudo docker tag [image name]:[tag] [username]:[tag]
sudo docker push [username]:[tag]
After the image is pushed, you can log in to Docker Hub to view the image.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback