docker to combat the deployment of static pages mirrored by nginx

  In this chapter we explain how to build a major container nginx by docker, here we deploy a static html for the material to demonstrate.

  First, we find nginx mirror on Docker Hub docker search nginx by [command]:

  

  Here we pull the official mirror on it, [command] nginx docker pull through.

  After pulling finished, we look at the local mirror list] [docker images:

  

  nginx already has several other mirrors do not control, I used the time to do anything else demo.

  Well, there is a mirror nginx later, we will be able to build a container containing nginx by this image, by this vessel, we can run our demo project.

  Before building container, we first prepare our material, that is, static html and nginx configuration, I am here to build a home directory on centos, there are two application and config folder, a file storage website publishers, a storage configuration. FIG respective path and file:

  

  demo.html which no content, just a standard html file, default.conf nginx configuration file is deployed Web site:

   

  listen port is the default 80 can be, this is the site's internal port on the server, the external network through this port is not accessible site. By the time the vessel will do port mapping operation, reassigning ports for external network access. Server_name localhost represents the local write back to, location inside the root represents nginx deployment site where the file path, since we are deploying the container, so the / app directory path here is actually a container. index is a start, we can set our demo.html.

  Nginx configuration file and website ready in the future we can start to build our container through nginx mirror, container has its own directory, but for ease of operation and do persist, we will run through the docker container -v parameter do directory is mounted.

  Command to run the container [docker run -d -p 8086: 80 -v / home / application / demo: / app -v /home/config:/etc/nginx/conf.d --name demo nginx]

  First of all I am concerned about these parameters, docker run is meant to run a container, -d represents the background -p 8086: 80 to 80 represent the internal port mapping to port 8086 on the external network, -v represents mount directory, The format is host -v directory: container directory. The above command we specify the file path and resource website nginx configuration, corresponding to the two documents before us in the host's home which put the file folder.

  After his string will appear after executing the above command, that means the success:        

  

  Then we come to see that we are running through the container [] docker ps command:

  

  You can see a demo of the named vessel is already running, in order from left to right we can see the container id, image-based, command execution, creation time, status, port, vessel name.

  Finally, we can open the page we deploy over IP + port of the form:

  

  

  Remarks:

  Place above tutorial Note: If you purchased a new server, or the server is not familiar with the students, the practice later discovered ip + port open deployed sites, so in most cases we must check whether the development of the corresponding port on the server, to bloggers, for example, using Ali cloud server, the security group rules, the relevant ports are open. Further, referred to herein a mount directory operation, this operation may be mounted to the sink host directory container directories, to achieve sustainable of container, log image data files are generally within the container, ah, ah generated, are available through mounted manner linked to the host, so that even if the container did not, the host will be a log file. Another point is that, if you do not like to mount this operation, that later had to later remove the container and then delete the files in the folder the host is too much trouble, and their business scenarios do not need sustainable, then when you create a container, -v command may not be used, but directly create, so after successfully created, to achieve the copy operation host file to the directory container by docker cp command, the command format is docker cp host directory: directory container, the specific use me here much talked about, everyone practice the line.

 

Guess you like

Origin www.cnblogs.com/sunshine-wy/p/11310865.html