一.Nginx是什么?
Nginx是十分轻量级的HTTP服务器。Nginx,它的发音为“engine X”,是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器。Nginx是由俄罗斯人 Igor Sysoev为俄罗斯访问量第二的 Rambler.ru站点开发的,它已经在该站点运行超过两年半了。Igor Sysoev在建立的项目时,使用基于BSD许可
1.下载Nginx镜像
docker pull nginx
2.检查当前所有docker下载的镜像
docker images
3.创建Nginx配置文件
# 创建挂载目录 mkdir -p /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/conf mkdir -p /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/log mkdir -p /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/html
容器中的nginx.conf文件和conf.d文件夹复制到宿主机
# 生成容器 docker run --name nginx -p 9379:80 -d nginx # 将容器nginx.conf文件复制到宿主机 docker cp nginx:/etc/nginx/nginx.conf /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/conf/nginx.conf # 将容器conf.d文件夹下内容复制到宿主机 docker cp nginx:/etc/nginx/conf.d /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/conf/conf.d # 将容器中的html文件夹复制到宿主机 docker cp nginx:/usr/share/nginx/html /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/
4.创建Nginx容器并运行
# 直接执行docker rm nginx或者以容器id方式关闭容器 # 找到nginx对应的容器id docker ps -a # 关闭该容器 docker stop nginx # 删除该容器 docker rm nginx
构建容器:
docker run --privileged=true -e TZ="Asia/Shanghai" -it -d --name nginx -p 9379:80 -p 13306:8080 -v /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/html:/etc/nginx/html -v /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST/logs:/var/log/nginx -v /opt/data/tmp1/jenkins_home/workspace/YAPI_API_AUTO_TEST:/home nginx
5.结果检测
6、 nginx.conf文件配置示例(docker方式部署location路径需要填写容器内部的路径 ):
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 8080; server_name test; location / { root /home; index report_test.html; } } }
标签:容器,nginx,YAPI,Nginx,API,conf,home,Docker,docker From: https://www.cnblogs.com/xfbk/p/17631423.html