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
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
Help Center/ Huawei Cloud EulerOS/ User Guide/ Creating a Docker Image and Starting a Container

Creating a Docker Image and Starting a Container

Updated on 2024-09-14 GMT+08:00

This section describes how you can create a Docker image for HCE and start the container on HCE.

Constraints

  • The version of HCE running the container image must be the same as that of the created container image.

Creating an Image Archive File

  1. Confirm that the repository is configured correctly.

    Check whether the parameters in the /etc/yum.repos.d/hce.repo file are configured correctly. The correct configuration is as follows:

    [base]
    name=HCE $releasever base
    baseurl=https://repo.huaweicloud.com/hce/$releasever/os/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.huaweicloud.com/hce/$releasever/os/RPM-GPG-KEY-HCE-2
    
    [updates]
    name=HCE $releasever updates
    baseurl=https://repo.huaweicloud.com/hce/$releasever/updates/$basearch/
    ......
  2. Create a temporary directory as the root system file of the Docker image and install the software package in the temporary directory.
    rm -rf /tmp/docker_rootfs 
    mkdir -p /tmp/docker_rootfs 
    yum --setopt=install_weak_deps=False --installroot /tmp/docker_rootfs --releasever 2.0 install bash yum coreutils security-tool procps-ng vim-minimal tar findutils filesystem hce-repos hce-rootfiles cronie -y
    CAUTION:
    • Replace releasever in the command with the HCE version number.
    • You can also install other required software packages here, but ensure that the space in the /tmp directory is sufficient.
  3. Go to the temporary directory of the chroot file system.
    chroot /tmp/docker_rootfs

    1. Execute HCE security-tool.sh to disable unnecessary services.
      export EULEROS_SECURITY=0
      echo "export TMOUT=300" >> /etc/bashrc
      /usr/sbin/security-tool.sh -d / -c /etc/hce_security/hwsecurity/hce_security_install.conf -u /etc/hce_security/usr-security.conf -l /var/log/hce-security.log -s

      During the execution, it is normal if the following errors are displayed:

      • The service file was not found. The service is not started in the chroot file system.
      • The /etc/sysconfig/init file for booting the system was not found. The tool disables services during system startup. The image rootfs is not involved in system startup.
      • The /proc/sys/kernel/sysrq file was not found. This file is used for calling after the system is started and does not exist in the chroot file system.

    2. Uninstall the security-tool, cronie, and systemd software packages and their dependent software packages.
      cp -af /etc/pam.d /etc/pam.d.bak
      rm -f /etc/yum/protected.d/sudo.conf /etc/yum/protected.d/systemd.conf
      yum remove -y security-tool cronie systemd
      rpm -e --nodeps logrotate crontabs
      rm -rf /etc/pam.d
      mv /etc/pam.d.bak /etc/pam.d
      sh -c 'shopt -s globstar; for f in $(ls /**/*.rpmsave); do rm -f $f; done'
      [ -d /var/lib/dnf ] && rm -rf /var/lib/dnf/*
      [ -d /var/lib/rpm ] && rm -rf /var/lib/rpm/__db.*
    3. Remove the /boot directory.
      rm -rf /boot
    4. Set the container image language to en_US.
      cd /usr/lib/locale;rm -rf $(ls | grep -v en_US | grep -vw C.utf8 )
      rm -rf /usr/share/locale/*
    5. Remove shared files man, doc, info, and mime.
      rm -rf /usr/share/{man,doc,info,mime}
    6. Remove the cached log files.
      rm -rf /etc/ld.so.cache
      [ -d /var/cache/ldconfig ] && rm -rf /var/cache/ldconfig/*
      [ -d /var/cache/dnf ] && rm -rf /var/cache/dnf/*
      [ -d /var/log ] && rm -rf /var/log/*.log
    7. Remove the Java security certificate.
      rm -rf /etc/pki/ca-trust/extracted/java/cacerts /etc/pki/java/cacerts
    8. Remove /etc/machine-id.
      rm -rf /etc/machine-id
    9. Remove /etc/mtab.
      rm -rf /etc/mtab
  4. Exit from the chroot file system.
    exit
  5. Compress the temporary directory and generate the Docker image archive file hce-docker.x86_64.tar.xz.
    The archive path is /tmp/docker_rootfs/hce-docker.x86_64.tar.xz.
    pushd /tmp/docker_rootfs/
    tar cvf hce-docker.x86_64.tar .
    xz hce-docker.x86_64.tar
    popd
  6. Convert the image archive file to a file with layer information.

    You cannot run the docker load command to load the image because the generated image archive file does not contain layer information. You need to run the docker import command to generate an image from the image archive file, and then run the docker save command to save the image as an image file with layer information. In this way, you can run the docker load command to load the image. In the following example, the image archive file is docker_save.tar.xz and the image is named my_image.

    docker import hce-docker.x86_64.tar.xz my_image:v1
    docker save -o docker_save.tar.xz my_image:v1

    You can run the docker load command to load the docker_save.tar.xz file.

    docker load -i docker_save.tar.xz

Starting a Container Using an Image Archive File

  1. Confirm that the repository is configured correctly.

    Check whether the parameters in the /etc/yum.repos.d/hce.repo file are configured correctly. The correct configuration is as follows:

    [base]
    name=HCE $releasever base
    baseurl=https://repo.huaweicloud.com/hce/$releasever/os/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.huaweicloud.com/hce/$releasever/os/RPM-GPG-KEY-HCE-2
    
    [updates]
    name=HCE $releasever updates
    baseurl=https://repo.huaweicloud.com/hce/$releasever/updates/$basearch/
    ......
  2. Install the Docker software package.
    yum install docker -y
  3. Use the image archive file to create a container image.
    mv /tmp/docker_rootfs/hce-docker.x86_64.tar.xz .
    docker import hce-docker.x86_64.tar.xz

    Run the docker images command to check the container image ID. In this example, the container image ID is 6cfefae3a541.

    NOTE:

    To create an image, you can run the following command to specify the REPOSITORY and TAG parameters:

    docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

  4. Run the image bash script in the container.

    If the shell view changes after you run the following command, you have started the bash for the container:

    docker run -it 6cfefae3a541 bash 

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