Docker中怎么运行nginx并挂载本地目录到镜像中

这篇“Docker中怎么运行nginx并挂载本地目录到镜像中”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Docker中怎么运行nginx并挂载本地目录到镜像中”文章吧。

10多年的鄠邑网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整鄠邑建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“鄠邑网站设计”,“鄠邑网站推广”以来,每个客户项目都认真落实执行。

创新互联网站建设公司是一家服务多年做网站建设策划设计制作的公司,为广大用户提供了成都网站设计、成都网站制作,成都网站设计,广告投放,成都做网站选创新互联,贴合企业需求,高性价比,满足客户不同层次的需求一站式服务欢迎致电。

1 从hup上pull镜像

docker pull nginx

2 创建将要挂载的目录

mkdir -p /data/nginx/{conf,conf.d,html,logs}

3 先要有配置文件才能启动容器

3.1 vim /data/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;
}

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; 
    # root  /usr/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; 
  #} 
}

4 启动容器

#将容器中nginx的80端口映射到本地的81端口
docker run --name nginx81 -d -p 81:80 -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 -d nginx:latest

5 查看启动的容器

[root@dc01 ~]# docker ps
container id image command created status ports names
fa56f865bd26 nginx:latest "nginx -g 'daemon of…" 4 weeks ago up 3 seconds 0.0.0.0:80->80/tcp vigilant_swirles
[root@dc01 ~]#

6 网页访问nginx

Docker中怎么运行nginx并挂载本地目录到镜像中

以上就是关于“Docker中怎么运行nginx并挂载本地目录到镜像中”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。

当前标题:Docker中怎么运行nginx并挂载本地目录到镜像中
网页路径:https://www.cdcxhl.com/article0/igchoo.html

成都网站建设公司_创新互联,为您提供定制网站网站内链网站导航小程序开发定制开发网站营销

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站建设