Updated on 2025-10-09 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 an application and its dependencies into a portable container and run the container on a Linux server to build, deploy, and manage the application more efficiently. This section describes how to install Docker in HCE.

Preparations

Prepare an ECS.

Prerequisites

A yum repository has been configured. For details, see Configuring Repositories and Installing Software for HCE.

Procedure

  1. Install Docker.

    1. Install Docker.
      dnf install docker

  2. Verify that Docker is installed.

    1. Start Docker.
      systemctl start docker
    2. Check the Docker version. If a version is displayed, Docker is installed successfully.
      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 the image.
      docker load -i <nginx_latest.tar file path>
    • Change the image tag.
      # Change the tag of the nginx image from latest to v1.
      docker tag nginx:latest nginx:v1
    • Check existing images.
      docker images
    • Delete the image.
      docker rmi 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>[:<Tag>]]

      Example:

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