Container Engine Basics
A container engine is one of the most important Kubernetes components. It is used to manage the lifecycle of images and containers. You can use it to create lightweight, portable, and self-sufficient containers for any application easily.
SWR supports two types of container engines: Docker and containerd. This section uses Docker as an example to describe how to install a container engine and use it to create an image file.
Preparations
Before installing Docker, get a basic understanding of what Docker is and how it works. For more information, see Docker Documentation.
Selecting a Docker Version
Docker is compatible with almost all operating systems. Select a Docker version that best suits your needs. If you are not sure which version to use, see https://docs.docker.com/engine/install/.

- To use Docker to push images to SWR, the Docker version must be between 1.11.2 (included) and 24.0.9 (included).
- Bind an elastic IP address (EIP) first if your server runs in a private network because Docker installation requires Internet connection.
Installing Docker
You can select either of the following installation procedures based on your OS.
- Linux
Run the commands to install the latest version. To install a specific version, see Install Docker Engine.
curl -fsSL get.docker.com -o get-docker.sh sh get-docker.sh sudo systemctl daemon-reload sudo systemctl restart docker
- EulerOS
- Log in to the ECS where you want to install Docker.
- Configure a yum repository.
If you have not configured a yum repository on the ECS, configure one. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)? If you have configured one, skip this step.
- Install and run Docker.
- Obtain the docker-engine package from the yum repository.
yum search docker-engine
- Run yum install -y to install the docker-engine package. The following is an example for x86:
yum install docker-engine.x86_64 -y
- Enable Docker to start at system startup.
- Start Docker.
- Obtain the docker-engine package from the yum repository.
- Verify the installation.
If information similar to the following is displayed, Docker is installed successfully:
Docker version 18.09.0, build 384e3e9
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 from a base Nginx image to change the welcome message to Hello, SWR!
- Log in to the server running Docker as root.
- Create a file named Dockerfile.
mkdir mynginx
cd mynginx
touch Dockerfile
- Edit Dockerfile.
vim Dockerfile
Add the following instructions to 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 layer. The format is RUN <command>. In this example, the echo command is executed to display Hello, SWR!
Press Esc and enter :wq to save the changes and exit.
- Run docker build [options] <context path> to build an image.
docker build -t nginx:v1 .
- -t nginx:v1: indicates the image name and tag.
- .: indicates the directory where the Dockerfile is located. All content in this directory will be packed and sent to Docker to build an image.
- Show all images. You can see the new image nginx:v1.
docker images
Creating an Image Package
This section describes how to compress a container image into a .tar or .tar.gz package.
- Log in to the server running Docker as root.
- Show all images.
docker images
Check the name and tag of the image to be compressed.
- Compress the image into a package.
docker save [OPTIONS] IMAGE [IMAGE...]
OPTIONS: You can set it to --output or -o, indicating that the image will be exported to a file.
The file should be in either .tar or .tar.gz format.
When using docker save to create an image package, use {image}:{tag} instead of image id. Otherwise, the package cannot be uploaded on the SWR console.
Example:
$ 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 # Package the nginx image of all tags. $ docker save -o nginx-latest.tar nginx:latest
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot