未加星标

CentOS7 Docker Nginx部署及运行详解

字体大小 | |
[运维安全 所属分类 运维安全 | 发布者 店小二04 | 时间 | 作者 红领巾 ] 0人收藏点击收藏
网上找了一些资料部署,出现不一样的问题,现在总结一下自己的部署流程。
1、资源准备

Dockerfile文件

# "ported" by Adam Miller <[email protected]> from
# https://github.com/fedora-cloud/Fedora-Dockerfiles
#
# Originally written for Fedora-Dockerfiles by
# scollier <[email protected]>

FROM centos:centos7
MAINTAINER The CentOS Project <[email protected]>

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 thephp 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、执行构建镜像命令

复制代码 代码如下:

[[email protected] nginx]# sudo docker build --rm --tag os7/nginx:centos7 . 

执行结果截图:

CentOS7 Docker Nginx部署及运行详解

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

CentOS7 Docker Nginx部署及运行详解
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

CentOS7 Docker Nginx部署及运行详解

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

CentOS7 Docker Nginx部署及运行详解

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

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

CentOS7 Docker Nginx部署及运行详解
8、接着在容器里面执行(直接输入即可)
nginx

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

CentOS7 Docker Nginx部署及运行详解

成功了。

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

CentOS7 Docker Nginx部署及运行详解

到此为止就成功了。

参考资料:https://github.com/CentOS/CentOS-Dockerfiles

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

本文运维安全相关术语:linux服务器代维 linux服务器搭建 运维管理 运维工程师 企业安全文章 企业安全管理 cf安全系统检测到游戏数据异常

主题: DockerNginxPHP浏览器CGHIG
分页:12
转载请注明
本文标题:CentOS7 Docker Nginx部署及运行详解
本站链接:http://www.codesec.net/view/563531.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 运维安全 | 评论(0) | 阅读(66)