千家信息网

CentOS7 Docker Nginx部署及运行的方法

发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,今天小编给大家分享一下CentOS7 Docker Nginx部署及运行的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文
千家信息网最后更新 2025年02月07日CentOS7 Docker Nginx部署及运行的方法

今天小编给大家分享一下CentOS7 Docker Nginx部署及运行的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

1、资源准备

dockerfile文件

# "ported" by adam miller  from #  https://github.com/fedora-cloud/fedora-dockerfiles # # originally written for fedora-dockerfiles by #  scollier   from centos:centos7 maintainer the centos project   run yum -y update; yum clean all run yum -y install epel-release tar ; yum clean all run yum -y install nginx ; yum clean all add nginx.conf /opt/deploy/nginx/nginx.conf run echo "daemon off;" >> /opt/deploy/nginx/nginx.conf #run curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ #  | tar -xz -c /usr/local/nginx/html \ #  --strip-components=1 #run sed -i -e 's/apache/nginx/g' -e '/apache_pb.gif/d' \  #  /usr/local/nginx/html/index.html  expose 80  #cmd [ "/usr/local/nginx/sbin" ]

注意:路径需要在系统上面存在以及对应

nginx.conf文件

# for more information on configuration, see: #  * official english documentation: http://nginx.org/en/docs/ #  * official russian documentation: http://nginx.org/ru/docs/  user nginx; worker_processes 1;  error_log /usr/logs/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info;  pid    /run/nginx.pid;   events {   worker_connections 1024; }   http {   include    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 /usr/logs/nginx/access.log main;    sendfile    on;   #tcp_nopush   on;    #keepalive_timeout 0;   keepalive_timeout 65;    #gzip on;    # load modular configuration files from the /etc/nginx/conf.d directory.   # see http://nginx.org/en/docs/ngx_core_module.html#include   # for more information.   #include /etc/nginx/conf.d/*.conf;    index  index.html index.htm;    server {     listen    80;     server_name localhost;     root     /usr/share/nginx/html;      #charset koi8-r;      #access_log /var/log/nginx/host.access.log main;      location / {       autoindex on;     }      # redirect server error pages to the static page /40x.html     #     error_page 404       /404.html;     location = /40x.html {     }      # redirect server error pages to the static page /50x.html     #     error_page  500 502 503 504 /50x.html;     location = /50x.html {     }      # proxy the php scripts to apache listening on 127.0.0.1:80     #     #location ~ \.php$ {     #  proxy_pass  http://127.0.0.1;     #}      # pass the php scripts to fastcgi server listening on 127.0.0.1:9000     #     #location ~ \.php$ {     #  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;     #}   }     # another virtual host using mix of ip-, name-, and port-based configuration   #   #server {   #  listen    8000;   #  listen    somename:8080;   #  server_name somename alias another.alias;   #  root     html;    #  location / {   #  }   #}     # https server   #   #server {   #  listen    443;   #  server_name localhost;   #  root     html;    #  ssl         on;   #  ssl_certificate   cert.pem;   #  ssl_certificate_key cert.key;    #  ssl_session_timeout 5m;    #  ssl_protocols sslv2 sslv3 tlsv1;   #  ssl_ciphers high:!anull:!md5;   #  ssl_prefer_server_ciphers  on;    #  location / {   #  }   #}  }

注意:路径需要在系统上面存在以及对应

2、执行构建镜像命令

复制代码 代码如下:


[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 .

执行结果截图:

3、查看镜像是否安装构建成功 docker images

4、创建容器 docker run -i -t -d -p 192.168.32.129:81:80 os7/nginx /bin/bash

注意:192.168.32.129这个ip的话,则需要在/etc/hosts中添加

192.168.32.129 localhost

5、查看容器是否创建成功并启动 docker ps

6、测试是否成功访问 curl http://192.168.32.129:81

会出现这个拒绝连接,那怎么办呢?有办法解决的,我们先进入该容器里面

7、进入容器 docker exec -i -t small_hodgkin /bin/sh

8、接着在容器里面执行(直接输入即可)

nginx

9、在容器外面执行 curl http://192.168.32.129:81

成功了。

10、再到虚拟机外面通过浏览器访问

以上就是"CentOS7 Docker Nginx部署及运行的方法"这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注行业资讯频道。

容器 成功 知识 篇文章 方法 运行 代码 内容 文件 系统 路径 镜像 不同 很大 办法 命令 大部分 就是 怎么办 截图 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 计算机组网和网络安全哪个好用 后端和云服务器 虹口区大型软件开发收费 珠海嵌入式软件开发哪家好 数据库中角色有那两种 国家那个部门负责网络安全 网络安全总体情况 北京特色软件开发厂家报价 崇明区特定网络技术开发优缺点 怀旧服如何切换数据库 宝鸡库克酷网络技术有限公司 南充创新网络技术有限公司 智慧停车系统数据库及技术架构图 全球学术快报服务器忙怎么回事 哈尔滨软件开发求职 工业4.0 软件开发服务 计算机软件开发开题报告 获取数据库中所有表名 网络安全的三定是什么 软件开发不符合问题表 云服务器应用租用多少钱 申威服务器什么架构 网络安全师怎么翻译 网络安全法所禁止的行为 在传统模式中孤岛网络技术 如何做部队网络安全教育课 软件开发项目绩效考核标准 网络安全小视频手抄报 电脑代理服务器连接失败 山东钢材供应链服务软件开发商
0