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 documentation. About OS Versions
This document uses CentOS 8.2 as examples for CVM instance OSs.
If you are using a TencentOS Server OS, perform operations based on the actual version:
TencentOS Server 2.4: a Docker image is preset, and you do not need to install Docker again. You can use Docker directly by referring to Using Docker. TencentOS Server 3.1 (TK4): build Docker according to the directions in this document.
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
Proceed according to the actual operating system version.
CentOS 8.2
2. Run the following command to add the Docker repository.
dnf config-manager --add-repo=http://mirrors.tencent.com/docker-ce/linux/centos/docker-ce.repo
3. Run the following command to view the added Docker repository.
4. Run the following command to install Docker.
dnf install -y docker-ce --nobest
5. Run the following command to run Docker.
6. Run the following command to check the installation result.
If you see the following prompt, it indicates that Docker has been successfully installed.
Using Docker
You can use Docker with the following commands:
Manage the Docker daemon.
Run the Docker daemon.
Stop the Docker daemon.
Restart the Docker daemon.
Manage images. This document uses the Nginx image of Docker Hub as an example.
Modify image tag to help you identify the image.
docker tag docker.io/nginx:latest tencentyun/nginx:v1
Query existing images.
Forcibly delete an image.
docker rmi -f tencentyun/nginx:v1
Manage containers.
Enter a container.
docker run -it ImageId /bin/bash
Run the docker images
command to obtain the ImageId
value.
Exit the container. Run the exit
command to exit the container.
Enter a container running in the background.
docker exec -it container ID /bin/bash
Create an image from the container.
docker commit <container ID or container name> [<repository name>[:<tag>]]
For example:
docker commit 1c23456cd7**** tencentyun/nginx:v2
Creating images
1. Run the following command to open the “Dockerfile” file.
2. Press i to switch to the edit mode and enter the following:
FROM tencentyun/nginx:v2
MAINTAINER DTSTACK
RUN mkdir /dtstact
ENTRYPOINT ping https://cloud.tencent.com/
3. Click Esc and enter :wq to save and close the file.
4. Run the following command to build an image.
docker build -t nginxos:v1 .
5. Run the following command to check if the image has been created.
6. Run the following commands in sequence to run and check the container.
docker run -d nginxos:v1
docker ps
docker ps -a
docker logs CONTAINER ID/IMAGE
7. Run the following commands in sequence to create an image.
docker commit fb2844b6**** nginxweb:v2
docker images
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
.
docker login
docker tag [image name]:[tag] [username]:[tag]
docker push [username]:[tag]
After the image is pushed, you can log in to Docker Hub to view the image.
Was this page helpful?