Manually Deploying Docker (CentOS 7.5)
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.
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
- Log in to the ECS.
- 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?
- Add a yum repository.
yum clean all
- Install yum-utils.
- Configure the yum repository for Docker.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- Install and run Docker.
systemctl enable docker
systemctl start docker
- Check the installation.
If the information similar to the following is displayed, Docker has been installed:
Docker version 26.1.4, build 5650f9b
Basic Operations on Docker
- Managing Docker processes
- Managing Docker images
- Managing containers
- 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".
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:
- Check whether the container has been started.
- 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.
- Create a container and run it.
Creating an Image
Use Dockerfile to customize a simple Nginx image.
- Create a file named Dockerfile.
mkdir mynginx
cd mynginx
touch Dockerfile
- Edit the file.
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.
- Build the image.
- -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.
- Check the created Nginx image, the version of which is v3.
REPOSITORY TAG IMAGE ID CREATED SIZE nginx v3 09422e465d96 10 seconds ago 109 MB
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