1.1 从hup上pull镜像
1.2 创建将要挂载的目录
1.3 先要有配置文件才能启动容器
1.3.1 vim /data/nginx/conf/nginx.conf
1.3.2 vim /data/nginx/conf.d/default.conf
1.4 启动容器
1.5 查看启动的容器
1.6 网页访问nginx

1.1 从hup上pull镜像
# docker pull nginx

1.2 创建将要挂载的目录
# mkdir -p /data/nginx/{conf,conf.d,html,logs}

1.3 先要有配置文件才能启动容器
1.3.1 vim /data/nginx/conf/nginx.conf

user  nginx;
worker_processes 1; error_log /var/log/nginx/error.log warn;
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;
}

1.3.2 vim /data/nginx/conf.d/default.conf

server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
root /data/nginx/html; #注意:记得写镜像对应的路径,可别写卷物理路径
index index.html index.htm;
autoindex on;
try_files $uri /index/index/page.html;
#try_files $uri /index/map/page.html;
} #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 ~ \.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;
#}
}

1.4 启动容器
#将容器中nginx的80端口映射到本地的81端口

docker run --name nginx_erp_test -d -p 80:80 -v /www/html/attachment:/www/html/attachment -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d nginx

注:-v /www/html/attachment:/www/html/attachment 图片存储路径,对应的配置如下:

#注意:要放在"location / {"上面
location ~ .*\.(gif|jpg|jpeg|png)$ {
expires 24h;
root /www/html/attachment;#指定图片存放路径
}

1.5 查看启动的容器
# docker ps

1.6 网页访问nginx
# curl http://localhost

1.7、nginx域名解析

server {
listen 80;
server_name erpshopwebservertest.xinyartech.com;
root /usr/share/nginx/html/test/;
access_log /usr/share/nginx/html/test/.log main;
#log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for';
error_log /usr/share/nginx/html/test/pay_local.error;
client_max_body_size 60M;
client_body_buffer_size 512k;
location / {
proxy_pass http://172.1.22.25:8082;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# rewrite ^(.*) https://$server_name$1 permanent;
}

Docker中运行nginx并挂载本地目录到镜像中的更多相关文章

  1. Docker中运行nginx

    Docker中运行nginx 1.Docker中运行nginx 2.配置文件 2.1 nginx.conf 2.2 default.conf 3.docker的镜像可以挂什么卷 部分内容原文地址: C ...

  2. docker挂载本地目录和数据卷容器

    1.docker挂载本地目录 docker可以支持把一个宿主机上的目录挂载到镜像里. 交互模式运行docker run -it -v /home/dock/Downloads:/usr/Downloa ...

  3. docker挂载本地目录的方法总结

    docker挂载本地目录的方法总结: Docker容器启动的时候,如果要挂载宿主机的一个目录,可以用-v参数指定. 譬如我要启动一个centos容器,宿主机的/test目录挂载到容器的/soft目录, ...

  4. oracle定时器,调用存储过程,定时从n张表中取值新增到本地一张表中

    --创建新增本地数据库的存储过程create or replaceprocedure pro_electric_record as  begin    insert into electric_met ...

  5. 3.键盘输入10个数,放到数组中,(1)去除该数组中大于10的数 (2)将该数组中的数字写入到本地文件number.txt中

    package cn.it.text; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; ...

  6. 使用docker-compose运行nginx容器挂载时遇到的文件/目录问题

    单独使用docker run命令指定挂载文件路径运行nginx容器是可以的,但是用在docker-compose中就不行了 报错如下: 原因就是挂载出错,不能直接挂载文件,还有挂载的容器里的目录要正确 ...

  7. 运维笔记--给正在运行的Docker容器动态绑定卷组(挂载指定目录)

    场景描述: 操作系统: ubuntu16.04, docker版本: Docker version 19.03.1 系统运行一段时间后,该服务器上有一个运行中docker容器,需要在容器里边挂载本地服 ...

  8. [Docker] Win10中安装Docker并运行Nginx镜像

    一.安装Docker 进入官网:https://www.docker.com/products/docker-desktop 可能需要先注册登录,很简单的. 点击 Download Desktop f ...

  9. docker基础知识之挂载本地目录

    docker可以支持把一个宿主机上的目录挂载到镜像里. docker run -it -v /home/dock/Downloads:/usr/Downloads ubuntu64 /bin/bash ...

随机推荐

  1. 唉 调皮的ListView

    唉 调皮的ListView 本次任务是 运用LisTView和自定义Adapter 来实现资料以列表的形式展现 来看代码 *** 布局代码老规矩 直接贴上 <LinearLayout andro ...

  2. python语法之函数1

    函数 计算机中的函数和数学中的函数不是一回事,而是一个subroutine .子程序.procedures.过程. 作用: 1.减少重复代码: 2.方便修改,更易扩展: 3.保持代码的一致性. 最简单 ...

  3. django的视图函数

    一.视图函数view 视图函数是接收一个请求(request对象),并返回响应的函数 1. HttpResponse响应请求 这个方法是返回字符串一类的,可以识别标签 2. render响应请求 re ...

  4. Vue控制路由滚动行为

    跳转路由时,要求跳转到指定路由的某个地方,可以使用scrollBehavior方法控制. 用法: scrollBehavior(to,from,savedPosition){   } scrollBe ...

  5. 文件上传的三种模式-Java

    文件上传的三种方式-Java 前言:因自己负责的项目(jetty内嵌启动的SpringMvc)中需要实现文件上传,而自己对java文件上传这一块未接触过,且对 Http 协议较模糊,故这次采用渐进的方 ...

  6. Freeradius服务器的搭建流程

    Freeradius服务器的搭建流程 一.服务器方面的配置 1 .安装radius服务器,数据库扩展插件 预先安装mysql数据库,然后安装freeradius,以及freeradius的数据库扩展插 ...

  7. 记一次bash脚本开发的经历

    现状描述与需求描述 最近梳理系统功能的时候发现现在每个月处理完数据之后,需要给别的系统传送批接口文件,接口文件的内容是来自于Oracle数据表中的数据.我每次都需要手工执行一下存储过程,让数据从正式表 ...

  8. Spring使用Autowiring自动装配 解决提示报错小技巧

    1.打开Settings   输入Inspections  找到Spring --> Spring Core --> Code --> Autowiring  for  Bean  ...

  9. poj 3159

    差分约束 我也忘了谁说的了,反正我记得有人说过,只要是差分约束问题都可以转换成图 至少目前看来都是这样的 我一开始spfa+queue超时 看别人博客才知道要用spfa+stack,感觉智商又下降了一 ...

  10. zabbix环境搭建

    zabbix介绍 zabbix是一个开源的监控软件集成了nagos和cat的优势 而且有很多自带的插件可以使用,而且还有api接口供我们使用 zabbix还支持自定义监控项 初始环境- centos ...