Updated on 2026-08-27 GMT+08:00

Manually Deploying Docker

Introduction

This section describes how to manually deploy Docker on a Linux FlexusL instance on Huawei Cloud, and provides common Docker operations and a simple image creation process.

Table 1 Docker terminologies

Term

Description

Docker

Docker is a platform for developers and system administrators to develop, deploy, and run applications using containers.

Docker image

Docker image is a special file system, which provides the programs, libraries, resources, and configuration files required for running containers. A Docker image also contains configuration parameters, for example, for anonymous disks, environment variables, and users. A Docker image does not contain any dynamic data, and its content remains unchanged after being built.

Container

Images become containers at runtime, that is, containers are created from images. A container can be created, started, stopped, deleted, and suspended.

This section uses CentOS 7.5 64bit (40 GiB), Debian 12.0.0 64bit, and Ubuntu 22.04 as examples. Docker requires a 64-bit OS with a kernel version of 3.10 or later.

Prerequisites

  • You have purchased a FlexusL instance and the instance is in the running state.
  • The security group rules listed in the following table have been added to the security groups that the FlexusL instance belongs to. For details, see Configuring Security Group Rules for a FlexusL Instance.
    Table 2 Security group rules

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Deploying Docker

Perform the following operations based on the OS.

  1. Log in to the FlexusL console.
  2. On the target resource card, choose > Reset Password to reset the password as instructed.

    A FlexusL instance does not have an initial password. If you want to log in to a FlexusL instance, set a password for it first. If you have already set a password, skip this step.

    For details, see Resetting the Password for a FlexusL Instance.

  3. Locate the target resource card and click Remote Login. In the displayed dialog box, click VNC Login and enter the username and password to log in to the FlexusL instance. The username is root, and the password is the one you set in the previous step.

    For more login methods, see Login Modes.

  4. Log in to the cloud server and add the Yum repository.
    yum install epel-release -y
    yum clean all
  5. Install yum-utils.
    yum install -y yum-utils device-mapper-persistent-data lvm2
  6. Configure the Docker Yum repository.
    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  7. Install and run Docker.
    yum -y install docker-ce
    systemctl enable docker
    systemctl start docker
  8. Check the installation result.
    docker --version

    If information similar to the following is displayed, Docker has been installed:

    Docker version 26.1.4, build 5650f9b
  1. Log in to the FlexusL console.
  2. On the target resource card, choose > Reset Password to reset the password as instructed.

    A FlexusL instance does not have an initial password. If you want to log in to a FlexusL instance, set a password for it first. If you have already set a password, skip this step.

    For details, see Resetting the Password for a FlexusL Instance.

  3. Locate the target resource card and click Remote Login. In the displayed dialog box, click VNC Login and enter the username and password to log in to the FlexusL instance. The username is root, and the password is the one you set in the previous step.

    For more login methods, see Login Modes.

  4. Log in to the cloud server and update the software package list.
    sudo apt-get update
  5. Add the Docker software package repository.
    sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
    sudo curl -fsSL https://mirrors.huaweicloud.com/docker-ce/linux/debian/gpg | sudo apt-key add -
    sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] https://mirrors.huaweicloud.com/docker-ce/linux/debian $(lsb_release -cs) stable"
  6. Install and run Docker.
    sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    sudo systemctl start docker
    sudo systemctl enable docker
  7. Check the Docker version.
    docker -v

    If information similar to the following is displayed, Docker has been installed:

    Docker version 28.3.3, build 980b856
  1. Log in to the FlexusL console.
  2. On the target resource card, choose > Reset Password to reset the password as instructed.

    A FlexusL instance does not have an initial password. If you want to log in to a FlexusL instance, set a password for it first. If you have already set a password, skip this step.

    For details, see Resetting the Password for a FlexusL Instance.

  3. Locate the target resource card and click Remote Login. In the displayed dialog box, click VNC Login and enter the username and password to log in to the FlexusL instance. The username is root, and the password is the one you set in the previous step.

    For more login methods, see Login Modes.

  4. Log in to the cloud server and update the software package list.
    sudo apt-get update
  5. Add the Docker software package repository.
    sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
    sudo curl -fsSL https://mirrors.huaweicloud.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] https://mirrors.huaweicloud.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  6. Install and run Docker.
    sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    sudo systemctl start docker
    sudo systemctl enable docker
  7. Check the Docker version.
    docker -v

    If information similar to the following is displayed, Docker has been installed:

    Docker version 28.3.3, build 980b856

Basic Operations on Docker

  1. Manage Docker processes.
    • Start Docker.

      systemctl start docker

    • Stop Docker.

      systemctl stop docker

    • Restart Docker.

      systemctl restart docker

  2. Manage images.
    1. Pull docker images. The official Apache and CentOS images are used as an example.

      docker pull httpd

      docker pull centos

    2. View existing images.

      docker images

    3. Forcibly delete an image.

      docker rmi centos

  3. Manage containers.
    1. Create a container and run it.

      docker run -it -d -p 80:80 --name datahttpd -v /data/:/var/www/httpd/ httpd

      The parameters are as follows:

      • -i: runs the container in interactive mode, which is usually used with -t.
      • -t: reallocates a pseudo input terminal to the container. This parameter is usually used with -i.
      • -d: runs the container at the backend and returns the container ID.
      • -p: maps ports, in the format of "Host port:Container port".
      • --name: specifies a name for the container.
      • -v: mounts an absolute directory on the host to the image, in the format of "Directory on the host:Mount path in the image".

      In the parameters, the host refers to the target ECS.

      In this example, a container is created and run from the httpd image in interactive mode. Port 80 of the container is mapped to port 80 of the host. The /data directory of the host is mapped to the /var/www/httpd directory of the container. The container ID will be returned.

    2. Check whether the container has been started.

      docker ps -a

    3. Enter the EIP of the FlexusL instance in the address bar of the browser and check the container running status. If the following information is displayed, the container is running properly.

Creating an Image

Use Dockerfile to customize a simple Nginx image.

  1. Create a file named Dockerfile.

    mkdir mynginx

    cd mynginx

    touch Dockerfile

  2. Edit Dockerfile.

    vim Dockerfile

    Add the following data to the file:

    FROM nginx
    RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html

    Simple Dockerfile commands are as follows (for more information, log in at https://docs.docker.com):

    • FROM statement (mandatory): must be the first instruction in Dockerfile, indicating that the Nginx image is used as a basic image.
    • RUN statement: indicates that the echo command is executed with the message "Hello, Docker!" displayed on the screen.
  3. Build the image.

    docker build -t nginx:v3 .

    • -t nginx:v3: specifies the image name and version.
    • .: specifies the context path. After the image-built command is executed, all data in the path will be packed to the Docker engine to build the image.
  4. Check the created Nginx image, the version of which is v3.

    docker images