CentOS7 Docker Nginx部署及运行详解
作者:lvk618 发布时间:2023-11-03 01:27:33
标签:CentOS7,Docker,Nginx
网上找了一些资料部署,出现不一样的问题,现在总结一下自己的部署流程。
1、资源准备
Dockerfile文件
# "ported" by Adam Miller <maxamillion@fedoraproject.org> from
# https://github.com/fedora-cloud/Fedora-Dockerfiles
#
# Originally written for Fedora-Dockerfiles by
# scollier <scollier@redhat.com>
FROM centos:centos7
MAINTAINER The CentOS Project <cloud-ops@centos.org>
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、再到虚拟机外面通过浏览器访问
到此为止就成功了。
参考资料:https://github.com/CentOS/CentOS-Dockerfiles
来源:http://blog.csdn.net/lk10207160511/article/details/51449762


猜你喜欢
- 有趣的是,用链接文本方式或者其他方法做关键词优化的索引页有时也不能占据前10名搜索结果的位置,但相同域名的内页仍可以做到,至少排名在前20名
- 一般来说我们采用手动备份VPS中的网站就可以了。一般老左喜欢1周备份一次网站,这样的频率应该还算是不错的,对于昨天分享的”数据库/网站文件自
- 本文记录了VMware Workstation14 Pro安装UBuntu17.04的具体方法,供大家参考,具体内容如下UBuntu之前用c
- 影响版本:DedeCms V 5.3程序介绍:DedeCms 基于PHP+MySQL的技术开发,支持Windows、Linux、Unix等多
- ARP(Address Resolution Protocol,地址解析协议)是一个位于TCP/IP协议栈中的低层协议,负责将某个IP地址解
- 千橡公司和kaixin001关于“开心网”名称归属的官司尚未了结,千橡已经把针对kaixin001的
- godaddy空间的邮件帐户的POP该怎样设置呢?下面我来给大家介绍下:第一. 创建帐户。第二. 具体的POP设置如下: &nbs
- 记得 KesionCMS V5.5版本新版快报时和大家分享了“超强互动推广积分计划功能”,受到了广大科汛粉丝的热烈反映,也有不少网友在跟帖中
- 网络冲浪者对Google情有独钟,是由于Google所提供的快速搜索速度及高命中率搜索结果。这些都是基于Google的复杂文本匹配运算法则及
- 这些天为了图床的事情弄得焦头烂额!后来在网上搜了一圈,发现其实可以自己搭建图床,这样就没有必要仰人鼻息了!我才想起我在godaddy注册了那
- 跨站脚本的名称源自于这样一个事实,即一个Web 站点(或者人)可以把他们的选择的代码越过安全边界线注射到另一个不同的、有漏洞的Web 站点中
- 1.域名轰炸域名轰炸,英文称:domain spamSEO新手往往会认为,注册N个域名,都连向主站,这样就可以增加主站的PR。如果这N个域名
- 随着站点规模的扩大,在线人数的上升,免费空间已经不适用了,就很有必要为自己选择一款收费空间,下面先简单介绍下国外的主机类型,大致分这么几种,
- 做SEO,关键词的优化是其中一个重要的部分,做关键词的优化,站长很容易陷入到两种极端,一种极端是专门做热门的关键词的优化,称之为红海战术;另
- 由于产品的需要,最近在配置apache的负载均衡功能,但是在配置虚拟主机的访问权限的时候我们遇到了一些问题。主要问题是deny和allow的
- 10月12日消息,据国外媒体报道,安全研究人员日前公布了谷歌Android移动平台的两处漏洞。开源计算机响应小组(oCert)称,这两处漏洞
- 今日淘特Asp.Net CMs推出2.0版,系统新增加了Tag标签,会员投稿,发布网站地图等功能。淘特Asp.Net Cms(V2.0) 2
- 马云坚信阿里巴巴将为世界创造更多财富,并成为与通用电气、微软一样伟大的企业。在9月10日晚的“阿里巴巴十周年庆典&
- 如果问哪种FTP服务器最安全?那么在Unix和Linux中,首推的就是vsftpd(Very Secure FTP Daemon,非常安全的
- 以前常有些个人站长或才进网络公司做推广合作的朋友在QQ或MSN上问我老谢,如何推广自己的网站或公司的网站。才开始的时候,我还会针对他们的网站