ECS training camp Day2 build Docker environment

Quickly build a Docker environment and deploy an Nginx service using Docker.

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 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 dependent packages into a portable container, and then publish it to any popular Linux machine or Windows machine. It can also be virtualized. The container is Full use of sandbox mechanism, there will be no interfaces between each other. The two technologies of Linux's 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

Install Docker CE

There are two branch versions of Docker: Docker CE and Docker EE, 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
  2. Add the software source information of Docker CE.
    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3. 安装Docker CE。
    yum makecache fast
    yum -y install docker-ce
  4. 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 Alibaba Cloud Mirror Warehouse.

  1. Log in to the container mirroring service console. https://homenew.console.aliyun.com/
    Insert picture description here

  2. The login success page is as follows.
    Insert picture description here

  3. Click [Mirror Center]> [Mirror Accelerator], you can see that Alibaba Cloud provides you with a dedicated mirror acceleration address.
    Insert picture description here

  4. Configure Docker's custom mirror warehouse address. Please replace the mirror warehouse address https://qbzpcp7m.mirror.aliyuncs.com in the command below with the exclusive mirror acceleration address provided by Alibaba Cloud.

tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://qbzpcp7m.mirror.aliyuncs.com"]
}
EOF
  1. Reload the service configuration file.
    systemctl daemon-reload
  2. 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
    Insert picture description here

  2. Pull the latest version of Nginx mirror.
    docker pull nginx:latest
    Insert picture description here

  3. View the local mirror.
    docker images
    Insert picture description here

  4. Run the container.
    docker run --name nginx-test -p 8080:80 -d nginx
    command parameter description:
    Insert picture description here

-- name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地8080端口映射到容器内部的80端口。
-d nginx: 设置容器在后台一直运行。
  1. Enter http://<ECS public network address>:8080 in the browser address bar to access the Nginx service.
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_39578545/article/details/108756897