Manually Deploying Docker (CentOS 7.5)
Overview
This best practice guides 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 that 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
Inbound
1
Allow
IPv4
TCP: 80
0.0.0.0/0
Resource Planning
Table 3 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.
Resource |
Description |
Cost |
---|---|---|
VPC |
VPC CIDR block: 192.168.0.0/16 |
Free |
VPC subnet |
|
Free |
Security group |
|
Free |
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
Docker |
Download URL: |
Free |
Deploying Docker
- Log in to the ECS.
- Add a yum repository.
yum install epel-release -y yum clean all
- Install yum-utils.
yum install -y yum-utils device-mapper-persistent-data lvm2
- Configure the yum repository for Docker.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- Install and run Docker.
yum -y install docker-ce systemctl enable docker systemctl start docker
- 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
- Managing Docker processes
- Start Docker.
systemctl start docker
- Stop Docker.
systemctl stop docker
- Restart Docker.
systemctl restart docker
- Start Docker.
- Managing Docker images
- Pull docker images. The official Apache and CentOS images are used as an example.
docker pull httpd docker pull centos
- View existing images.
docker images
- Forcibly delete an image.
docker rmi centos
- Pull docker images. The official Apache and CentOS images are used as an example.
- 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: maps ports, 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.
In this example, a container is created and run from the httpd image in interactive mode. Port 80 of the container is mapped to port 80 of the host. The /data directory of the host is mapped to the /var/www/httpd directory of the container. The container ID will be returned.
- Check whether the container has been started.
docker ps -a
- 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 Dockerfile.
vim Dockerfile
Add the following data to the file:
FROM nginx RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
Dockerfile commands are described below. For more information, log in at https://docs.docker.com.
- FROM: must be the first instruction in Dockerfile, indicating that the Nginx image is used as a basic image. This statement is mandatory.
- RUN: indicates that the echo command is executed with the message "Hello, Docker!" displayed on the screen.
- 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.
- 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
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