网站首页 > 技术教程 正文
目标
通过dockerfile定制自己的nginx,可生产使用
模版
一个需要三个文件
[root@localhost nginx]# ls default.conf Dockerfile nginx.repo
- default.conf 是我的nginx转发配置文件
- Dockerfile 是docker的配置文件
- nginx.repo 容器安装nginx的yum镜像
分别看下
//default.conf server { listen 80; server_name localhost; location / { // 测试地址,我采用宿主机的ip端口,开的web服务 proxy_pass http://192.168.1.110:8080/; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx"; } } //Dockerfile,采用centos7作为标准镜像,不用nginx标准镜像原因是因为那样启动的容器是mina版的linux,太简单 FROM centos:centos7 #MAINTAINER 维护者信息 MAINTAINER fendo kai.yang@yeepay.com ADD default.conf /etc/nginx/conf.d/ ADD nginx.repo /etc/yum.repos.d/ #RUN 执行以下命令 RUN yum install -y nginx #EXPOSE 映射端口 EXPOSE 80 #CMD 运行以下命令,daemon off后台运行,否则启动完就自动关闭 CMD ["/usr/sbin/nginx", "-g","daemon off;"] // nginx.repo ,用于yum直接安装nginx [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
操作
- 首先进入文件所在目录
[root@localhost nginx]# cd /apps/nginx/
- 构建镜像,切记最后有个点,否则会报错( requires exactly 1 argument)
- [root@localhost nginx]# docker build -t nginx10 .
- 查看镜像
[root@localhost nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx10 latest dd7d54fef2f3 12 minutes ago 283MB
- 运行镜像
[root@localhost nginx]# docker run -d -p 8888:80 -p 90:80 dd7d54fef2f3
解释一下,-p 8888:80 -p 90:80表示将宿主机的8888和90都映射到容器的80端口,因为nginx.conf配置的是监听容器的80端口,所以访问宿主机的这两个端口都会触发转发逻辑。同理,如果容器中nginx需要监听多个端口时,也可以借用这种方式配置。看下效果
访问90端口
猜你喜欢
- 2024-10-16 manifest.json在微前端中的妙用(manifest vue)
- 2024-10-16 Nginx源码分析(五)(nginx开源)
- 2024-10-16 Docker 循序渐进之实例部署(docker-curriculum)
- 2024-10-16 做服务的负载均衡,你也可以(docker 中部署 nginx)
- 2024-10-16 蓝易云 - Docker安装Nginx,并实现负载均衡教程。
- 2024-10-16 RHEL9/ALMA9 搭配portainer docker容器管理面板进行应用部署
- 2024-10-16 本地电脑使用Docker 构建Nginx + Vue项目
- 2024-10-16 在 Docker 中部署 Nginx 并挂载配置文件
- 2024-10-16 Nginx docker 镜像使用(docker中的nginx镜像运行后的主要功能是什么)
- 2024-10-16 用了8年的方式-用 Docker 瞬间搭建本地开发环境
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)