网站首页 > 技术教程 正文
1. 介绍
1.1 介绍
大家根福哥学会了使用Dockerfile创建Docker镜像的技巧了,那么我们现在搭建服务器环境就不需要再去下载软件的源代码了,也不需要编译安装了,更加不用操心软件和操作系统的各种兼容问题了。
今天福哥带着大家来安装nginx的环境,Nginx常用作web服务的出口服务器,代理各种应用服务器的功能集中到一起发布出去。
2. 镜像
2.1 tag
Nginx的标签有很多,福哥选择的是1.20版本。
2.2 结构
照例我们先把镜像拉取下来,然后启动一个容器,看看里面都有什么,弄明白了自己才好捣鼓啊!
2.2.1 拉取镜像
docker pull nginx:1.20
2.2.2 启动临时容器
docker run -tid --name nginx1.20 -h nginx1.20 nginx:1.20
2.2.3 切入临时容器
docker exec -ti nginx1.20 /bin/bash
2.2.4 查看结构
进入容器后,全局查找一番,发现原来nginx的配置文件路径在/etc/nginx/nginx.conf。
[root@dev ~]# docker exec -ti nginx1.20 /bin/bash
root@nginx1:/# find / -iname "*nginx*"
/etc/rc5.d/S01nginx
/etc/rc6.d/K01nginx
/etc/logrotate.d/nginx
/etc/init.d/nginx-debug
/etc/init.d/nginx
/etc/default/nginx-debug
/etc/default/nginx
/etc/systemd/system/multi-user.target.wants/nginx.service
/etc/rc0.d/K01nginx
/etc/rc1.d/K01nginx
/etc/rc2.d/S01nginx
/etc/rc3.d/S01nginx
/etc/rc4.d/S01nginx
/etc/nginx
/etc/nginx/nginx.conf
/usr/lib/nginx
/usr/sbin/nginx-debug
/usr/sbin/nginx
/usr/share/doc/nginx-module-xslt
/usr/share/doc/nginx-module-geoip
/usr/share/doc/nginx-module-image-filter
/usr/share/doc/nginx
/usr/share/doc/nginx-module-njs
/usr/share/nginx
/var/lib/dpkg/info/nginx-module-image-filter.list
/var/lib/dpkg/info/nginx-module-image-filter.md5sums
/var/lib/dpkg/info/nginx.postinst
/var/lib/dpkg/info/nginx-module-geoip.list
/var/lib/dpkg/info/nginx.md5sums
/var/lib/dpkg/info/nginx-module-njs.list
/var/lib/dpkg/info/nginx-module-njs.postinst
/var/lib/dpkg/info/nginx-module-image-filter.postinst
/var/lib/dpkg/info/nginx-module-geoip.postinst
/var/lib/dpkg/info/nginx-module-xslt.list
/var/lib/dpkg/info/nginx-module-njs.md5sums
/var/lib/dpkg/info/nginx.list
/var/lib/dpkg/info/nginx-module-xslt.md5sums
/var/lib/dpkg/info/nginx-module-xslt.postinst
/var/lib/dpkg/info/nginx.postrm
/var/lib/dpkg/info/nginx.prerm
/var/lib/dpkg/info/nginx-module-geoip.md5sums
/var/lib/dpkg/info/nginx.preinst
/var/lib/dpkg/info/nginx.conffiles
/var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/nginx.service
/var/lib/systemd/deb-systemd-helper-enabled/nginx.service.dsh-also
/var/lib/systemd/deb-systemd-helper-enabled/nginx-debug.service.dsh-also
/var/cache/nginx
/var/log/nginx
/lib/systemd/system/nginx.service
/lib/systemd/system/nginx-debug.service
/run/nginx.pid
find: '/proc/1/map_files': Operation not permitted
find: '/proc/30/map_files': Operation not permitted
find: '/proc/31/map_files': Operation not permitted
find: '/proc/32/map_files': Operation not permitted
find: '/proc/37/map_files': Operation not permitted
使用curl测试一下,可用看到nginx默认的首页。
2.2.5 停止临时容器
docker stop nginx1.20
2.2.6 删除临时容器
docker rm nginx1.20
3. Dockerfile
最后福哥把前面的设置命令整理到一起写成Dockerfile,这样大家就可以通过Dockerfile安装环境了。
3.1 nginx.conf
默认的nginx.conf是这样的,可用看出具体的配置文件在/etc/nginx/conf.d/下面。
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;
}
3.2 default.conf
进入conf.d目录下面发现只有一个default.conf配置文件,默认default.conf的内容是这样的。
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
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 ~ \.phpnbsp;{
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.phpnbsp;{
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
可以看到默认的配置文件里面以及给出了apache版本的php环境以及fpm版本的php环境接入nginx的示例配置方法。
3.3 Dockerfile
创建Dockerfile,因为Nginx是配合其他应用服务使用的,所以这里福哥没有做什么调整,咱们以后再结合项目进行具体的定制调整吧。
FROM nginx:1.20
MAINTAINER Andy Bogate
MAINTAINER tongfu@tongfu.net
MAINTAINER https://tongfu.net/dockerfile
MAINTAINER 2021/5/24
MAINTAINER v1.0.0
EXPOSE 80 443
4. 总结
今天福哥带着大家使用Dockerfile搭建了Nginx微服务环境了,可以发现使用Dockerfile方式搭建环境我们真的只需要关心我们需要关心的部分,繁琐的编译参数、依赖库、环境参数等等一系列的问题基础镜像都给我们解决好了。
下一课,福哥会带着搭建学习使用Dockerfile搭建Nginx+PHP环境,敬请期待~~
https://m.tongfu.net/home/35/blog/513309.html
猜你喜欢
- 2024-10-14 nginxWebUI 1.2.1 发布,nginx 图形化管理工具
- 2024-10-14 Nginx各个阶段(nginx的几种模式)
- 2024-10-14 centos7-nginx-1.12.2编译安装,不求人!
- 2024-10-14 【开源资讯】nginx 1.18.0 稳定版发布
- 2024-10-14 Nginx 1.14.2 移植指南(openEuler 20.03 LTS SP1)
- 2024-10-02 centos7 源码nginx1.16.1安装(nginx源码安装 linux)
- 2024-10-02 nginx 1.19.6 主线版发布(nginx/1.19.2)
- 2024-10-02 nginx 1.16.1 稳定版和 nginx 1.17.3 主线版发布 修复安全问题
- 2024-10-02 安装nginx1.17.0以及文件目录(nginx安装指定安装路径)
- 2024-10-02 Linux上安装Nginx1.8(linux nginx安装及配置教程)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (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)
本文暂时没有评论,来添加一个吧(●'◡'●)