Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Manually Deploying Docker (CentOS 7.5)

Updated on 2024-11-04 GMT+08:00

Overview

The best practices for Huawei Cloud ECS guide you through the manual deployment of Docker on a Linux ECS. Additionally, common Docker operations and the process of creating a Docker image are provided.

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.

For more information about Docker, image, and container, see Docker Documentation.

Docker requires 64bit OSs with a kernel version being 3.10 or later. This section uses CentOS 7.5 64bit (40 GiB) as an example.

Prerequisites

  • The target ECS has an EIP bound. For instructions about how to bind an EIP to an ECS, see Assigning an EIP.
  • The rule listed in the following table has been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
    Table 2 Security group rule

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source Address

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Deploying Docker

  1. Log in to the ECS.
  2. To obtain and update the system and software, update the image source to a Huawei Cloud image source. For details, see How Can I Use an EPEL Image Source (x86_64 or Arm) Provided by Huawei Cloud?
  3. Add a yum repository.

    yum install epel-release -y

    yum clean all

  4. Install yum-utils.

    yum install -y yum-utils device-mapper-persistent-data lvm2

  5. Configure the yum repository for Docker.

    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

  6. Install and run Docker.

    yum -y install docker-ce

    systemctl enable docker

    systemctl start docker

  7. Check the installation.

    docker --version

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

    Docker version 26.1.4, build 5650f9b

Basic Operations on Docker

  1. Managing Docker processes
    • Start Docker.

      systemctl start docker

    • Stop Docker.

      systemctl stop docker

    • Restart Docker.

      systemctl restart docker

  2. Managing Docker images
    1. Pull docker images, taking official Apache and CentOS images as an example.

      docker pull httpd

      docker pull centos

    2. View existing images.

      docker images

    3. Forcibly delete an image.

      docker rmi centos

  3. Managing 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: port mapping, 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".
      NOTE:

      In the preceding parameters, the host is the target ECS.

      For example, use image httpd to start a container in interactive mode, map port 80 on the container to port 80 on the host, and map /data on the host to /var/www/httpd on the container, and have the container ID returned. Then, run the following command:

    2. Check whether the container has been started.

      docker ps -a

    3. In the address bar of the browser, enter the EIP bound to the ECS and check the running status of the container. 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 the file.

    vim Dockerfile

    Add the following data to Dockerfile:

    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

    REPOSITORY          TAG             IMAGE ID              CREATED               SIZE
    nginx               v3              09422e465d96          10 seconds ago        109 MB

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback