Docker中运行nginx并挂载本地目录到镜像中
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并挂载本地目录到镜像中的更多相关文章
- Docker中运行nginx
Docker中运行nginx 1.Docker中运行nginx 2.配置文件 2.1 nginx.conf 2.2 default.conf 3.docker的镜像可以挂什么卷 部分内容原文地址: C ...
- docker挂载本地目录和数据卷容器
1.docker挂载本地目录 docker可以支持把一个宿主机上的目录挂载到镜像里. 交互模式运行docker run -it -v /home/dock/Downloads:/usr/Downloa ...
- docker挂载本地目录的方法总结
docker挂载本地目录的方法总结: Docker容器启动的时候,如果要挂载宿主机的一个目录,可以用-v参数指定. 譬如我要启动一个centos容器,宿主机的/test目录挂载到容器的/soft目录, ...
- oracle定时器,调用存储过程,定时从n张表中取值新增到本地一张表中
--创建新增本地数据库的存储过程create or replaceprocedure pro_electric_record as begin insert into electric_met ...
- 3.键盘输入10个数,放到数组中,(1)去除该数组中大于10的数 (2)将该数组中的数字写入到本地文件number.txt中
package cn.it.text; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; ...
- 使用docker-compose运行nginx容器挂载时遇到的文件/目录问题
单独使用docker run命令指定挂载文件路径运行nginx容器是可以的,但是用在docker-compose中就不行了 报错如下: 原因就是挂载出错,不能直接挂载文件,还有挂载的容器里的目录要正确 ...
- 运维笔记--给正在运行的Docker容器动态绑定卷组(挂载指定目录)
场景描述: 操作系统: ubuntu16.04, docker版本: Docker version 19.03.1 系统运行一段时间后,该服务器上有一个运行中docker容器,需要在容器里边挂载本地服 ...
- [Docker] Win10中安装Docker并运行Nginx镜像
一.安装Docker 进入官网:https://www.docker.com/products/docker-desktop 可能需要先注册登录,很简单的. 点击 Download Desktop f ...
- docker基础知识之挂载本地目录
docker可以支持把一个宿主机上的目录挂载到镜像里. docker run -it -v /home/dock/Downloads:/usr/Downloads ubuntu64 /bin/bash ...
随机推荐
- pip install cv2报错
pip install cv2 安装cv2报错: Could not find a version that satisfies the requirement cv2 (from versions: ...
- kali自定义分辨率(1920*1080)
运行一下两行代码: xrandr --newmode -hsync +vsync xrandr --addmode Virtual1 "1920x1080_60.00"
- consul搭建
1.准备3台服务器 linux1 192.168.0.101 linux2 192.168.0.102 linux3 192.168.0.103 2.准备向Linux上传文件的工具Winscp 3.去 ...
- spring学习(二)---依赖注入
spring第二个特性是依赖注入. 学习依赖注入,首先应该明白两个问题:1,谁依赖谁:2,谁注入,注入什么? 首先还是看代码: 还是这个bean: package testSpring.busines ...
- redis学习-列表(list)常用命令
redis学习-列表(list)常用命令 lpush:从列表左侧头部添加数据 rpush:从右侧尾部添加数据 lpop:从给左侧头部取出一个元素 rpop:从右侧尾部取出一个元素 lrange:取 ...
- Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂
https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...
- latex 希腊字母表示
http://blog.sina.com.cn/s/blog_5e16f1770100lxq5.html
- Django 信号、中间件、i18n 专题
信号 Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. 1. Django内置信号 Model signals pr ...
- CENTOS7常用的基础命令集合(一)
目录(?)[-] CentOS7 常用命令集合 常用命令 文件与目录操作 查看文件内容 文本内容处理 查询操作 压缩解压 yum安装器 网络相关 系统相关 系统服务启动相关 防火墙相关 RPM包管理 ...
- 协程 及 libco 介绍
libco 是腾讯开源的一个协程库,主要应用于微信后台RPC框架,下面我们从为什么使用协程.如何实现协程.libco使用等方面了解协程和libco. why协程 为什么使用协程,我们先从server框 ...