docker 建立nginx容器部署前端服務
阿新 • • 發佈:2021-08-17
1、搜尋nginx映象
docker search nginx
2、拉取映象
docker pull nginx名稱
3、建立test映象
docker run --name nginx-test -p 8080:80 -d nginx
4、訪問宿主ip和埠,檢視 nginx
5、從nginx-test測試容器中拷貝檔案到宿主機
docker cp nginx-test:/etc/nginx/nginx.conf /home/nginx/copadmin
5、nginx目錄掛在,必須在宿主機上有nginx.conf 檔案才可以掛在,所以在宿主進上建立 /nginx/config/nginx.conf配置檔案,配置檔案如下
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server { listen 8081; server_name 10.9.53.58; #charset koi8-r; location / { proxy_pass http://www.badu.com; #root /home/copfront/copfront.admin/dist; #index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_passhttp://127.0.0.1; #} } }
6、構建映象,並目錄掛載
docker run --name cop.admin.web -p 8001:80 -v /home/nginx/copadmin/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx -v /home/copfront/copfront.admin/:/usr/share/html -d nginx
7、將打包好的前端頁面直接放到對應的copfront.admin資料夾內就可以了
8、重啟docker 容器