zoukankan      html  css  js  c++  java
  • centos7安装docker详解和使用之nginx的使用(四)

    一,接着centos7安装docker详解和使用之.netcore的搭建和访问(三)的基础上,我们接着搭建nginx的使用

    1》我们先在添加一个实例容器

    docker run -itd -p 8082:80 dockerdemo

    2》我们查看下当前容器的数量

    docker ps -a

    有两个已经跑起来,好了,容器准备好了

     

     二,开始搭建ngnix

    1》查找下nginx

     docker search nginx

    我们发现第一个stars最多,肯定是下载第一个了

     2》我们拉取下nginx

    docker pull nginx

    拉取结果,成功

    docker images

    3》创建nginx映射目录

    mkdir -p /root/nginx/www /root/nginx/logs /root/nginx/conf

    4》镜像已经有了,我们构建nginx容器

    docker run -d -p 80:80 --name nginx-web  -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/logs:/var/log/nginx nginx

    命令详解:

    1,-d 后台运行

    2,-p映射端口

    3,-name别名

    4,-v目录映射

    查看下,nginx容器已经构建成功,由于没有设置端口,所以nginx默认监听80端口,如下图(80/tcp)

    5》nginx.conf文件配置

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
         upstream ngnxdemo{
        server 172.17.0.1:8081 weight=2;   //可访问容器地址
        server 172.17.0.1:8082 weight=1; 
    } 
        server {
        listen       80;
         server_name  localhost;
        location / {
        proxy_pass  http://ngnxdemo;  #集群地址,对应upstream 
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

    6》现在nginx的配置完了,我们可以访问linux的ip,因为默认80端口,去使用nginx的配置,访问容器

    查看容器信息(festive_wescoff:这个是容器名)

    docker inspect festive_wescoff

     7》如果我们修改了配置文件nginx.conf,执行命令,重启下容器即可

    docker restart 容器id

     8》容器停止(exit(0))后根据ID重启

    docker start 0005103b5a88
  • 相关阅读:
    写在之前
    Fedora Core 3安装杂记(三)
    Fedora Core 3安装杂记(一)
    Firefox 1.0真的挺好用的
    发现Google加了英文页面翻译功能(Beta)
    Fedora Core 3安装杂记(四)
    在FC3的日子里……
    ASP面向对象编程探讨及比较
    显卡千万不能买带风扇的……
    字符串(strcat)
  • 原文地址:https://www.cnblogs.com/May-day/p/14018117.html
Copyright © 2011-2022 走看看