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

Basics of the Container Engine

Updated on 2022-03-17 GMT+08:00

The container engine, namely, Docker, is an open-source engine which allows you to create a lightweight, portable, and self-sufficient container for any application. SWR is compatible with Docker, allowing you to use Docker CLI and APIs to manage your images.

Installing Docker

Before installing Docker, get a basic understanding of what Docker is and how it works. For more information, see Docker Documentation.

Docker is compatible with almost all operating systems. Select a Docker version that best suits your needs. If you are not sure which Docker community edition to use, see https://docs.docker.com/engine/install/.

NOTE:
  • Before using SWR to store container images, ensure that the Docker client used to push images to SWR is updated to 1.11.2 or later.
  • Bind an elastic IP address first if your server runs in a private network as the installation requires Internet connection.

On a device running Linux, run the following commands to quickly install Docker:

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
sudo systemctl daemon-reload
sudo systemctl restart docker

Building a Container Image

This section walks you through the steps of using a Dockerfile to build a container image for a simple web application. Dockerfile is a text file that contains all the instructions a user can call on the command line to build an image. A container image is a stack consisting of multiple layers. Each instruction creates a layer.

When using a browser to access a containerized application built from a Nginx image, you will see the default Nginx welcome page. In this section, you will build a new image based on the Nginx image to change the welcome message to Hello, SWR!

  1. Log in to the device running Docker as a root user.
  2. Run the following commands to create an empty file named Dockerfile:

    mkdir mynginx

    cd mynginx

    touch Dockerfile

  3. Edit Dockerfile.

    vim Dockerfile

    Add the following instructions to the Dockerfile:

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

    In the preceding instructions:

    • FROM: creates a layer from the base image. A valid Dockerfile must start with a FROM instruction. In this example, the Nginx image is used as the base image.
    • RUN: executes a command to create a new layer. One of its syntax forms is RUN <command>. In this example, the echo command is executed to display Hello, SWR!

    Save the changes and exit.

  4. Run docker build [option] <context path> to build an image.

    docker build -t nginx:v1 .

    • -t nginx:v1: specifies the image name and tag.
    • .: indicates the path where the Dockerfile is located. All contents in this path are packed and sent to the Docker to build an image.

  5. Run the following command to check the created image. The command output shows that the nginx image has been created with a tag of v1.

    docker images

Creating an Image Package

This section describes how to compress a container image into a .tar or .tar.gz package.

  1. Log in to the device running Docker as a root user.
  2. Run the following command to list images.

    docker images

    Check the name and tag of the image to be compressed.

  3. Run the following command to compress the image into a package.

    docker save [OPTIONS] IMAGE [IMAGE...]

    NOTE:

    OPTIONS: You can set this to --output or -o, indicating that the image is exported to a file.

    The file should be in either .tar or .tar.gz.

    Sample:

    $ docker save nginx:latest > nginx.tar
    $ ls -sh nginx.tar
    108M nginx.tar
    
    $ docker save php:5-apache > php.tar.gz
    $ ls -sh php.tar.gz
    372M php.tar.gz
    
    $ docker save --output nginx.tar nginx
    $ ls -sh nginx.tar
    108M nginx.tar
    
    $ docker save -o nginx-all.tar nginx
    $ docker save -o nginx-latest.tar nginx:latest

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