杰网资源 Design By www.escxy.com

这里来安装下Nginx试下。

注意要明确一点,镜像是类,容器是对象。

查看当前的镜像

Docker安装Nginx教程实现图例讲解

看到只有一个测试的镜像。

Docker安装Nginx教程实现图例讲解

拉取镜像:

下载成功后查看,镜像已经被下载下来了:

Docker安装Nginx教程实现图例讲解

使用 nginx 镜像

运行容器:

查看容器运行情况:

Docker安装Nginx教程实现图例讲解

然后在浏览器输入网址:

Docker安装Nginx教程实现图例讲解

修改文件:

[root@VM_0_4_centos bin]# docker ps
CONTAINER ID    IMAGE        COMMAND         CREATED       STATUS       PORTS        NAMES
 
8bf811453641    nginx        "nginx -g 'daemon of…"  4 minutes ago    Up 4 minutes    0.0.0.0:80->80/tcp  nginx_test

记住这里的 CONTAINER ID ,这是容器的ID

进入容器,修改:

[root@VM_0_4_centos bin]# docker exec -it 8bf811453641 /bin/bash
root@8bf811453641:/# cd /usr/share/nginx/html
root@8bf811453641:/usr/share/nginx/html# echo "hello docker">index.html
root@8bf811453641:/usr/share/nginx/html# exit

这是查看,修改的已经生效了。

Docker安装Nginx教程实现图例讲解

如果想停止容器:

docker stop containerId // containerId 是容器的ID
[root@VM_0_4_centos bin]# docker stop 8bf811453641

然后用docker ps 看容器运行状态就行。

到此,容器运行完毕,总体来说非常的简单。

下面追加挂载方法先创建目录

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

nginx配置文件

/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;

  server {
    listen    80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
      root  /usr/share/nginx/html;
      index index.html index.htm;
    }

    #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  html;
    }

  }
  
  include /etc/nginx/conf.d/*.conf;
}

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

/data/nginx/html/index.html

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>系统时间</title>
</head>
<body>
<h1 id="datetime">
  <script>
    setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 1000);
  </script>
</h1>
</body>

删除容器

docker rm -f nginx-test

重新映射启动容器

docker run --name nginx-test -d -p 80: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

再次运行

Docker安装Nginx教程实现图例讲解

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

标签:
Docker,安装,Nginx

杰网资源 Design By www.escxy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
杰网资源 Design By www.escxy.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。