Updated on 2025-07-18 GMT+08:00

Installing Docker

Introduction

Docker is an open-source application container engine that features portability, scalability, high security, and manageability. Developers can package applications and dependencies into portable containers, quickly release them to Linux servers, and use the OS-level virtualization to build, deploy, and manage applications more efficiently. This section describes how to install Docker in HCE 2.0.

Preparations

Prepare an ECS.

Prerequisites

A yum repository has been configured. For details about how to configure a yum repository accessed over the Internet, see Configuring Repositories and Installing Software for HCE.

Procedure

  1. Install Docker.

    1. Run the following command to install Docker:
      dnf install docker
    2. Run the following command to start Docker:
      systemctl start docker

  2. Verify that Docker is installed.

    If the Docker version is displayed, Docker is installed successfully, as shown in Figure 1.
    docker -v
    Figure 1 Checking whether Docker is installed successfully

Docker 18.09.0 is installed. To install a later version, see Docker Documentation.

Using Docker

  1. Manage the Docker daemon.
    • Run the daemon.
      systemctl start docker
    • Stop the daemon.
      systemctl stop docker
    • Restart the daemon.
      systemctl restart docker
  2. Manage images. The nginx image is used as an example. You need to prepare a local image file nginx_latest.tar.
    • Import a local image.
      docker load -i <nginx_latest.tar file path>
    • Edit the label.
      # Change the version of the nginx image from latest to v1.
      docker tag nginx:latest nginx:v1
    • View existing images.
      docker images
    • Forcibly delete an image.
      docker rmi -f nginx:v1
  3. Manage containers.
    • Start a container.
      # Create and start a container from an image. The image ID can be obtained by running docker images.
      docker run -it <image-ID> /bin/bash
    • Exit a container.
      exit
    • Start a container in the background.
      docker run -itd <image-ID>
    • Check all running containers.
      docker ps
    • Enter a container running in the background. You can run docker ps to obtain the container ID.
      docker exec -it <Container ID> /bin/bash
    • Create an image from the container. The container ID can be obtained by running docker ps.
      docker commit <Container ID> [<Repository name>[:<Label>]]

      Example:

      docker commit 135****9f757 nginx:v1