Huawei Cloud Yunyao Cloud Server L instance evaluation | Deploying nginx service on Docker based on Yunyao Cloud Server

1. Service introduction

Yunyao cloud server

Hyper Elastic Cloud Server (HECS) is a new generation cloud server that can quickly build simple applications. It has an independent and complete operating system and network functions, and is suitable for low-load application scenarios such as website construction and development environments.

Introduction to Docker

Docker is an open platform for developing, publishing, and running applications. Docker enables you to decouple applications from infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure just like your applications. By leveraging Docker's approach to shipping, testing, and deploying code, you can significantly reduce the latency between writing your code and running it in production.

Introduction to Docker-Compse

Compose is a tool for defining and running multi-container Docker applications. Compose lets you use YAML files to configure your application's services. Then, using a single command, you can create and start all services based on your configuration.

2. Install Docker on Yunyao Cloud Server

  • Confirm the Linux system version.
[root@hcss-ecs-2d95 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

image-20230914210805564

  • Update system
# sudo yum update -y

image-20230914211338964

  • Install docker using YUM source
[root@hcss-ecs-2d95 ~]# sudo yum list | grep docker
[root@hcss-ecs-2d95 ~]# sudo yum install -y docker

[root@hcss-ecs-2d95 ~]# rpm -qa | grep docker
docker-client-1.13.1-209.git7d71120.el7.centos.x86_64
docker-common-1.13.1-209.git7d71120.el7.centos.x86_64
docker-1.13.1-209.git7d71120.el7.centos.x86_64
  • Check docker version number
[root@hcss-ecs-2d95 ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon runni

At this time, the docker display status is not started.

  • Start the Docker service and enable the docker self-starting function.
[root@hcss-ecs-2d95 ~]# sudo systemctl start docker
[root@hcss-ecs-2d95 ~]# sudo systemctl enable docker
[root@hcss-ecs-2d95 ~]# sudo systemctl status docker

image-20230914211711192

  • View docker service
[root@hcss-ecs-2d95 ~]# ps aux | grep docker
root     11349  0.0  1.3 526784 26120 ?        Ssl  21:16   0:00 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json --selinux-enabled --log-driver=journald --signature-verification=false --storage-driver overlay2
root     11355  0.0  0.7 377616 13628 ?        Ssl  21:16   0:00 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc --runtime-args --systemd-cgroup=true
root     11471  0.0  0.0 112812   976 pts/0    S+   21:23   0:00 grep --color=auto docker

3. Run the nginx service through the Docker run command

  • The command to create nginx service using docker is as follows:
# sudo docker pull nginx
# sudo docker image ls
# sudo docker container run --name xybweb -d -p 80:80 -it --rm nginx
# sudo docker container ls -a
# sudo curl http://127.0.0.1
# sudo docker container stop xybweb
  • The specific command demonstration process is as follows:
[root@hcss-ecs-2d95 ~]# sudo docker pull nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
360eba32fa65: Pull complete
c5903f3678a7: Pull complete
27e923fb52d3: Pull complete
72de7d1ce3a4: Pull complete
94f34d60e454: Pull complete
e42dcfe1730b: Pull complete
907d1bb4e931: Pull complete
Digest: sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
Status: Downloaded newer image for docker.io/nginx:latest

[root@hcss-ecs-2d95 ~]# sudo docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              f5a6b296b8a2        6 days ago          187 MB

[root@hcss-ecs-2d95 ~]# sudo docker container run --name xybweb -d -p 80:80 -it --rm nginx
86e3b48a4294346cf256ddde40a58a6a736d0a5f717de94015e74092098d9659

[root@hcss-ecs-2d95 ~]# sudo docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS
    NAMES
86e3b48a4294        nginx               "/docker-entrypoin..."   35 seconds ago      Up 34 seconds       0.0.0.0:80->80/tcp   xybweb

[root@hcss-ecs-2d95 ~]# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html {
    
     color-scheme: light dark; }
body {
    
     width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

[root@hcss-ecs-2d95 ~]# sudo docker container stop xybweb
xybweb

image-20230914213043784

PS: If you cannot access this interface, please check whether the system firewall is closed or allow the corresponding port to pass. Please also check whether the security group of the cloud server has opened access port 80.

4. Install docker-compose on Yunyao Cloud Server

The command to install docker-compse is as follows:

# 下载插件
sudo curl -L "https://github.com/docker/compose/releases/download/2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

PS:若直接在云服务器中下载受阻,可以先将软件包下载到本地后,再上传到云服务器中。

# 授权
sudo chmod +x /usr/local/bin/docker-compose

# 查看docker-compose版本
docker-compose version

The specific installation steps are as follows:

[root@hcss-ecs-2d95 ~]# cp -r /mnt/xyb_share/docker-compose-linux-x86_64 /usr/local/bin/docker-compose

[root@hcss-ecs-2d95 ~]# sudo chmod +x /usr/local/bin/docker-compose

[root@hcss-ecs-2d95 ~]# docker-compose version
Docker Compose version v2.20.3

5. Start the nginx service through docker-compose

# vim docker-compose.yml
# cat docker-compose.yml
version: "3"
services:
  mynginx:
    image: nginx:stable-alpine
    ports:
    - "80:80"
    restart: always

# docker-compose build
# docker-compose up -d
# docker-compose ps
# nmap 127.0.0.1

image-20230914220642847

At this point, the experiment of using Huawei Cloud Yaoyun Server to install and deploy the docker service and using the docker command to build the nginx service is completed.


Guess you like

Origin blog.csdn.net/qq_45392321/article/details/132892210