In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to deploy static files in a Docker nginx container". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to deploy static files in a Docker nginx container".
Note: the version of Docker is as follows:
Client: Version: 17.12.0-ce API version: 1.35 Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:11:19 2017 OS/Arch: linux/amd64Server: Engine: Version: 17.12.0-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:09:53 2017 OS/Arch: linux/amd64 Experimental: false
I use ubuntu18. I have installed docker. After that, I need to have a nginx image. The nginx image I use is nginx:1.14.
The front end is separated from the front end, and the front end is deployed separately in nginx, but after installing nginx and reading the tutorial, I feel that I have to install a lot of things and many steps. Since docker is installed on the server, we use the nginx container instead of manually installing nginx.
1 create a volume named nginx
With the volume of docker, mount the directory of the nginx container to the local file of the host machine, so that we only need to modify the file of the corresponding directory in host, which is convenient for management.
List-1.1 creates a data volume using the docker volume create volume name
Xx@xx-ubuntu:/opt/software/nginx/html$ docker volume create nginxxx@xx-ubuntu:/opt/software/nginx/html$ docker volume lsDRIVER VOLUME NAMElocal nginx
As shown in the following List-1.2, use the docker volume inspect nginx command to view the data volume nginx you just created. You can see that this data volume corresponds to the local / var/lib/docker/volumes/nginx/_data directory. You will check this directory later, which will be covered in the following content.
List-1.2
Xx@xx-ubuntu:/opt/software/nginx/html$ docker volume inspect nginx [{"CreatedAt": "2018-12-18T20:18:41+08:00", "Driver": "local", "Labels": {}, "Mountpoint": "/ var/lib/docker/volumes/nginx/_data", "Name": "nginx", "Options": {} "Scope": "local"}] 2 create a container
Execute the command in the following List-2.1, which is worth noting here is the parameter "- v nginx:/etc/nginx", which means to mount the data volume nginx to the container's / etc/nginx directory
List-2.1
Xx@xx-ubuntu:/opt/software/nginx/conf$ docker run-d-v nginx:/etc/nginx-p 80:80-name nginx nginx:1.14
Check the local directory corresponding to the data volume nginx (we know the local directory corresponding to the data volume nginx according to List-1.2). As shown in the following List-2.2, there are a lot of things, these files are all nginx. Let's take a look at the nginx.conf file, as shown in List2.3. We can see that the key is the .conf file in the / etc/nginx/conf.d directory. By default, there is a default.conf. We copy default.conf and rename it to hello.conf. The content is as follows: List-2.5
List-2.2 needs to use root to check
Root@xx-ubuntu:/var/lib/docker/volumes/nginx/_data# lltotal 48drwxr-xr-x 3 root root 4096 December 18 20:18. / drwxr-xr-x 3 root root 4096 December 18 20:18.. / drwxr-xr-x 2 root root 4096 December 18 20:21 conf.d/-rw-r--r-- 1 root root 1007 November 6 21:28 fastcgi_params-rw-r--r-- 1 root root 2837 November 6 21:28 koi- Utf-rw-r--r-- 1 root root 2223 November 6 21:28 koi-win-rw-r--r-- 1 root root 5170 November 6 21:28 mime.typeslrwxrwxrwx 1 root root 22 November 6 21:28 modules- > / usr/lib/nginx/modules-rw-r--r-- 1 root root 643 November 6 21:28 nginx.conf-rw-r--r-- 1 root root 636 November 6 21:28 scgi_params-rw-r -- root root 1 root root 664 November 6 21:28 uwsgi_params-rw-r--r-- 1 root root 3610 November 6 21:28 win-utf
List-2.3 is viewed by root users
Root@xx-ubuntu:/var/lib/docker/volumes/nginx/_data# more nginx.conf... # contains all files ending with .conf in the / etc/nginx/conf.d directory include / etc/nginx/conf.d/*.conf;}
List-2.4 uses root users to operate
Root@xx-ubuntu:/var/lib/docker/volumes/nginx/_data/conf.d# lltotal 16drwxr-xr-x 2 root root 4096 December 18 20:21. / drwxr-xr-x 3 root root 4096 December 18 20:18.. /-rw-r--r-- 1 root root 1093 November 6 21:28 default.conf-rw-r--r-- 1 root root 1087 December 18 20:21 hello.conf
Other unnecessary content of List-2.5 was deleted by me.
Change the value of root@xx-ubuntu:/var/lib/docker/volumes/nginx/_data/conf.d# more hello.conf server {# listen to your desired port listen 3002; server_name localhost; # charset koi8-r; # access_log / var/log/nginx/host.access.log main The value of location / {# root can be changed to your own, indicating that there are static resources root / opt/html; index index.html index.htm;} that we want to access in this directory.
After the above, we create an index.html in the local directory, as shown in the following List-2.6
List-2.6
Xx@xx-ubuntu:/opt/software/nginx/html$ lltotal 12drwxr-xr-x 2 mjduan mjduan 4096 December 18 20:24. / drwxr-xr-x 4 mjduan mjduan 4096 December 18 20:22.. /-rw-r--r-- 1 mjduan mjduan 171December 18 20:24 index.html
After that, we delete the previously created container nginx, and then create another container, as shown in List-2.7:
List-2.7
Xx@xx-ubuntu:/opt/software/nginx/conf$ docker rm nginx nginxxx@xx-ubuntu:/opt/software/nginx/conf$ docker run-d-v nginx:/etc/nginx-v / opt/software/nginx/html:/opt/html-p 3002JV 3002-p 80:80-name nginx nginx:1.14
Note: in List-2.7, "- v nginx:/etc/nginx" is to mount the data volume nginx to the container's / etc/nginx directory, and "- v / opt/software/nginx/html:/opt/html" is to mount the local / opt/software/nginx/html directory to the container's / opt/html directory. Since we need port 3002 (set in List-2.5), we need to map it out.
Then access port 3002 in the browser, as shown in figure 2.1 below:
Figure 2.1 shows the index.html in List-2.6
Thank you for reading, the above is the content of "how to deploy static files in the Docker nginx container". After the study of this article, I believe you have a deeper understanding of how to deploy static files in the Docker nginx container. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.