Quickly build a Docker environment based on ECS cloud server

Quickly build a Docker environment based on ECS

Experience address: https://developer.aliyun.com/adc/scenario/9fd79b8711984e309f20d82bc65a26fa?spm=a2c6h.15013979.J_7591448770.12.380070778QJr1s

Experience goal

This scenario will provide an ECS instance (cloud server) configured with CentOS 7.7. Through the operations in this tutorial, you can quickly build a Docker environment based on an ECS instance, and deploy an Nginx service in the Docker environment.

background knowledge

Container technology

Container is a lightweight, operating system-level virtualization technology that allows us to run applications and their dependencies in the process of resource isolation. All necessary components required to run applications are packaged into a single image. This image It can be reused. When the image is running, it runs in an independent environment and does not share the memory, CPU, or disk of the host operating system with other applications. This ensures that the processes inside the container will not affect any processes outside the container.

Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable container, and then publish it to any popular Linux machine or Windows machine. It can also be virtualized. The container is completely Using the sandbox mechanism, there will be no interfaces between each other. The two technologies of Linux cgroup and namespace used at the bottom of Docker implement application isolation. A complete Docker consists of the following parts:

  • Docker Client client
  • Docker Daemon daemon
  • Docker Image mirror
  • Docker Container

Create resources

  1. On the left side of the page, click the drop-down menu of cloud product resources to view the resources of this experiment.

  2. Click Activate for free to create the required resources.

Note: The resource creation process takes 1~3 minutes. After completing the creation of experimental resources, you can view the created resource information in the cloud product resource list, such as: IP address, user name, and password.

Connect to ECS server

  1. Open the terminal tool that comes with the system.
  • Windows: CMD or Powershell.
  • MAC:Terminal。
  1. Enter the connection command ssh [username]@[ipaddress] in the terminal. You need to replace username and ipaddress with the login name and public network address of the ECS server created in Section 1. E.g:
ssh [email protected]

img

The command display results are as follows:

img

  1. Enter yes.

  2. After agreeing to continue, you will be prompted to enter the login password. The password is the login password of the ECS of the created cloud service.

img

After successful login, the following information will be displayed.

img

Install Docker CE

Docker has two branch versions: Docker CE and Docker EE, namely the community edition and the enterprise edition. This tutorial is based on CentOS 7 to install Docker CE.

  1. Install Docker's dependent libraries.
yum install -y yum-utils device-mapper-persistent-data lvm2
  1. Add the software source information of Docker CE.
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  1. Install Docker CE.
yum makecache fast
yum -y install docker-ce
  1. Start the Docker service.
systemctl start docker

Configure Alibaba Cloud Image Warehouse (Image Acceleration)

The default official remote repository of Docker is hub.docker.com . Due to network reasons, it may take a long time to download an official Docker image, and the download may even fail. To this end, Aliyun container mirroring service ACR provides an official mirror site to speed up the download of official mirrors. The following describes how to use the Alibaba Cloud image warehouse.

  1. Log in to the container mirroring service console.

a. On the left side of the page resource bar click a button to copy login url , open the login link incognito window (incognito mode) input has been copied.

img

. b Enter the resources available sub-user name and the sub-user password , click [Log]; then search the container mirroring, click [service] to log container mirrored console.

img

c. The login success page is as follows. (If the opening service window pops up, just close it)

img

  1. Click [Mirror Center]> [Mirror Accelerator], you can see that Alibaba Cloud provides you with a dedicated mirror acceleration address.

img

  1. Configure Docker's custom mirror warehouse address. Please replace the mirror warehouse address in the following command https://kqh8****.mirror.aliyuncs.comwith the exclusive mirror acceleration address provided by Alibaba Cloud.
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://kqh8****.mirror.aliyuncs.com"]
}
EOF
  1. Reload the service configuration file.
systemctl daemon-reload
  1. Restart the Docker service.
systemctl restart docker

Install Nginx service using Docker

  1. Check the available version of Nginx in the Docker mirror repository.
docker search nginx

The command output is as follows:

img

  1. Pull the latest version of Nginx mirror.
docker pull nginx:latest

The command output is as follows:

img

  1. View the local mirror.
docker images

The command output is as follows:

img

  1. Run the container.
docker run --name nginx-test -p 8080:80 -d nginx

Command parameter description:

  • --Name nginx-test: The name of the container.
  • -p 8080:80: port mapping, mapping the local 8080 port to the 80 port inside the container.
  • -d nginx: Set the container to always run in the background.

The command output is as follows:

img

  1. Enter to http://<ECS公网地址>:8080access the Nginx service in the browser address bar .

img

tee /etc/docker/daemon.json <<-‘EOF’ { “registry-mirrors”: [“https://ya7293gb.mirror.aliyuncs.com”] } EOF

Guess you like

Origin blog.csdn.net/weixin_43314519/article/details/113745577