Centos7 uses docker to deploy servers with one click


Docker is delicious

Check your system version before using docker
cat /etc/redhat-release
The following table directly shows docker’s requirements for several mainstream Linux system versions

operating system Supported system versions
CentOS CentOS 7
Debian Debian Wheezy 7.7 (LTS)
Debian Jessie 8 (LTS)
Debian Stretch 9
Debian Buster 10
Fedora Fedora 26
Fedora 27
Ubuntu Ubuntu Trusty 14.04 (LTS)
Ubuntu Xenial 16.04 (LTS)
Ubuntu Artful 17.10

Of course, docker can also be installed in a lower version of Linux system, but it can only be installed with a lower version. There are some missing functions or differences with the latest version. Therefore, if conditions permit, it is recommended to upgrade the system to a system version that supports the latest version of docker

Install docker

Download script

curl -fsSL https://get.docker.com -o get-docker.sh

Execute script

sh get-docker.sh

Using mirrors

Because if not, docker pull is turtle speed…
There are folders to omit this step
mkdir -p /etc/docker

tee /etc/docker/daemon.json <

{ "registry-mirrors": ["https://9cpn8tt6.mirror.aliyuncs.com"]}


systemctl daemon-reload

systemctl restart docker
You can use docker – V to see if docker is successfully installed

Install nginx

Use docker to run a nginx container. The docker container can be started in seconds and deleted when it is used up. Therefore, we need to make file persistent storage and mount the directory and configuration in the container that need to be persistent
The directory that nginx needs to be persistent is the location where we deploy the front end / usr / share / nginx / HTML,
The nginx configuration is also mounted to facilitate modification of / etc / nginx/ nginx.conf ,
In this way, we can deploy front-end static resources outside the container and modify nginx configuration. After modification, the container will be OK after restart.

Find a location, such as / home / nginx, and create a container temporarily to copy the configuration
docker run --name nginx --rm -d nginx
–RM means that the container is deleted after it stops
-D represents the background running container
–Name name the container
Using docker PS, you can see that the nginx container is running,
Copy the default configuration in the container to / home / nginx directory
docker cp nginx:/etc/nginx/nginx.conf /home/nginx

Stop container after copying
docker stop nginx
If you use docker PS – A to view the container, you will not see it
-A means to view all containers without looking at running containers

Now you can officially create the nginx container
docker run --restart-always --name nginx -d -p 80:80 -p 443:443 -v /home/nginx/html: /usr/share/nginx/html -v /home/nginx/nginx.conf:/etc/nginx/nginx.conf nginx
–Restart always ensures that the container is restarted under special circumstances
-P maps the port in the container to the host, – P [host port]: [port in container]
In this way, we can directly enter your server IP address in the browser to see the welcome page of nginx. Alicloud server also needs to open port 80 in the security group
-V is to map the directory in the container to the directory of the host, so that even if the container is deleted, our data still exists

In future deployment, you can put the static resources packaged by the front-end in the path / home / nginx / HTML, and then docker restart nginx is OK,


Even the static resources packaged each time in the front end can be docked to build an image. According to the version number, the static resources can be tagged, pushed to the docker hub, and the image can be used to run a volume container
With Jenkins, the front-end automatic packaging and deployment can be realized. As long as you submit the code to the warehouse, Jenkins can help you implement the front-end test = > package = > deploy an entire pipeline

I have just learned docker, and I welcome to point out the shortcomings.