Quickly build a Docker environment and deploy an Nginx service using Docker.
Docker environment
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.
- Install Docker's dependent libraries.
yum install -y yum-utils device-mapper-persistent-data lvm2 - Add the software source information of Docker CE.
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo - 安装Docker CE。
yum makecache fast
yum -y install docker-ce - 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.
-
Log in to the container mirroring service console. https://homenew.console.aliyun.com/
-
The login success page is as follows.
-
Click [Mirror Center]> [Mirror Accelerator], you can see that Alibaba Cloud provides you with a dedicated mirror acceleration address.
-
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
- Reload the service configuration file.
systemctl daemon-reload - Restart the Docker service.
systemctl restart docker
Install Nginx service using Docker
-
Check the available version of Nginx in the Docker mirror repository.
docker search nginx
-
Pull the latest version of Nginx mirror.
docker pull nginx:latest
-
View the local mirror.
docker images
-
Run the container.
docker run --name nginx-test -p 8080:80 -d nginx
command parameter description:
-- name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地8080端口映射到容器内部的80端口。
-d nginx: 设置容器在后台一直运行。
- Enter http://<ECS public network address>:8080 in the browser address bar to access the Nginx service.