zoukankan      html  css  js  c++  java
  • dokcer3

    安装好的文件位置:
    
    /usr/sbin/nginx:主程序
    
    /etc/nginx:存放配置文件
    
    /usr/share/nginx:存放静态文件
    
    /var/log/nginx:存放日志
    
    其实从上面的根目录文件夹可以知道,Linux系统的配置文件一般放在/etc,日志一般放在/var/log,运行的程序一般放在/usr/sbin或者/usr/bin。
    
    
    Nginx部署流程:

    root@ubuntu:/home/yw1989# docker run -p 80 --name nginx_web1 -i -t ubuntu /bin/bash 
    root@417a0dbc5500:/#  : 进入容器中(先apt-get update不然安装不了nginx)
    root@417a0dbc5500:/# apt-get install -y nginx  :  安装nginx
    root@417a0dbc5500:/# apt-get install -y vim : 安装vim
    root@3b1e8b137e4e:/# mkdir -p /var/www/html
    root@3b1e8b137e4e:/# cd /var/www/html
    root@3b1e8b137e4e:/var/www/html# vim index.html  :  编辑静态页面
    修改nginx配置文件:
    root@417a0dbc5500:/# whereis nginx
    nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
    root@3b1e8b137e4e:/usr/share/nginx# cd /etc/nginx
    root@3b1e8b137e4e:/etc/nginx# ls
    root@417a0dbc5500:/etc/nginx# ls
    conf.d          koi-utf     nginx.conf    sites-available  uwsgi_params
    fastcgi.conf    koi-win     proxy_params  sites-enabled    win-utf
    fastcgi_params  mime.types  scgi_params   snippets
    root@3b1e8b137e4e:/etc/nginx# cd sites-enabled/
    root@3b1e8b137e4e:/etc/nginx/sites-enabled# ls
    default
    root@3b1e8b137e4e:/etc/nginx/sites-enabled# vim default
    修改root的值为usr/www/html
    切换到根目录:运行nginx,
    root@417a0dbc5500:/# ps -ef : 容器里面查看当前进程,nginx已经运行起来了。
    UID         PID   PPID  C STIME TTY          TIME CMD
    root          1      0  0 11:56 pts/0    00:00:00 /bin/bash
    root        894      1  0 12:55 ?        00:00:00 nginx: master process nginx
    www-data    895    894  0 12:55 ?        00:00:00 nginx: worker process
    root        897      1  0 12:56 pts/0    00:00:00 ps -ef
    
    使用ctrl+P ctrl+Q来退出。是容器在后台运行。
    $docker ps 查看:
    417a0dbc5500        ubuntu              "/bin/bash"              About an hour ago   Up About an hour    0.0.0.0:32768->80/tcp   nginx_web1
    将容器的80端口映射到主机的32768端口上。
    root@ubuntu:/home/yw1989# docker port nginx_web1  :查看容器中端口映射情况
    80/tcp -> 0.0.0.0:32768
    root@ubuntu:/home/yw1989# docker top nginx_web1  : 查看容器中进程的情况
    UID   PID  PPID  C   STIME   TTY  TIME    CMD
    root  3578   3566  0  03:56   pts/0   00:00:00   /bin/bash
    Root  7505 3578  0  04:55   ?   00:00:00   nginx: master process nginx
    www-data   7506  7505     0   04:55  ?    00:00:00  nginx: worker process
    root@ubuntu:/home/yw1989# curl http://127.0.0.1:32768 :网站成功返回了刚才写的页面,虚拟机中使用http://127.0.0.1:32768/,http://172.17.0.2:80/可以访问,172.17.0.2是容器IP。在自己电脑http://192.168.115.129:32768/也可以访问(192.168.115.129是虚拟机的地址)。
    <html>
    <head>
      <title>fdfdsfdsfdsf</title>
    </head>
    
    <body>
    
    <h1>
    hhijhihii
    </h1>
    </body>
    
    </html>
    root@ubuntu:/home/yw1989# docker inspect nginx_web1 : 查看容器的ip地址
         "NetworkSettings": {
    "IPAddress": "172.17.0.2",
    
    $docker stop nginx_web : 停止容器
    
    nginx_web1
    root@ubuntu:/home/yw1989# docker start -i nginx_web1
    root@417a0dbc5500:/# ps -ef  :  关闭后停止并没有启动nginx,退出
    UID         PID   PPID  C STIME TTY          TIME CMD
    root          1      0  0 13:22 pts/0    00:00:00 /bin/bash
    root          9      1  0 13:22 pts/0    00:00:00 ps -ef
    root@ubuntu:/home/yw1989# docker exec nginx_web1 nginx   :  启动nginx
    root@ubuntu:/home/yw1989# docker top nginx_web1  :  查看到nginx再次启动了
    UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
    root                10527               10508               0                   05:22               pts/0               00:00:00            /bin/bash
    root                10718               10508               0                   05:24               ?                   00:00:00            nginx: master process nginx
    www-data            10719               10718               0                   05:24               ?                   00:00:00            nginx: worker process
    
    root@ubuntu:/home/yw1989# curl http://127.0.0.1:32768  :  访问失败
    curl: (7) Failed to connect to 127.0.0.1 port 32768: Connection refused
    root@ubuntu:/home/yw1989# docker inspect nginx_web1   :  ip地址和端口都变了
        "NetworkSettings": {
           "IPAddress": "172.17.0.2",
              "Ports": {
                    "80/tcp": [
                        {
                            "HostIp": "0.0.0.0",
                            "HostPort": "32769"
                        }
                    ]
                },
    停止一个容器并重新启动,ip地址和端口改变。
    查看和删除镜像:
    镜像是一种使用联合加载技术层叠的只读文件系统,是容器构建的基石。存储在/var/lib/docker,

    root@ubuntu:/# docker info
    Docker Root Dir: /var/lib/docker
    Containers: 4
     Running: 3
     Paused: 0
     Stopped: 1
    Images: 1
    Server Version: 18.01.0-ce
    Kernel Version: 4.10.0-28-generic
    Operating System: Ubuntu 16.04.3 LTS
    OSType: linux
    Architecture: x86_64
    CPUs: 1
    Total Memory: 971.6MiB
    Name: ubuntu

    root@ubuntu:/# docker images  : 列出所有的镜像
    REPOSITORY     TAG       IMAGE ID           CREATED        SIZE
    ubuntu         latest      0458a4468cbc       6 days ago          112MB
    REPOSITORY:镜像所属的仓库名
    TAG       :镜像的标签名
    IMAGE ID   :镜像的唯一id,就是镜像的文件名
    CREATED   :镜像建立的时间
    SIZE       :镜像的大小
    
    REPOSITORY仓库是一系列镜像的集合,一个仓库包含的是一系列关联的镜像,比如ubuntu就是一个大的仓库,这与docker组件中的仓库(registry)很大区别,组件的仓库提供的是docker镜像的存储服务,REPOSITORY仓库包含了很多registry仓库。
    
    Tag镜像的标签:在仓库中不同的镜像是以tag区分的,REPOSITORY仓库名加上标签名就构成了一个完整了镜像名字,这个镜像的名字就对应一个镜像的id。不同的标签可以对应相同的id名,就是说可以对不同的需求对镜像文件打上不同的标签。
    root@ubuntu:/# docker images --no-trunc  : 查看完整的id(上面是截断的id)
    REPOSITOR TAG IMAGE ID                                                                  CREATED             SIZE
    ubuntu              latest              sha256:0458a4468cbceea0c304de953305b059803f67693bad463dcbe7cce2c91ba670   6 days ago          112MB
    没有名字和标签的镜像就是中间层镜像。

    yw1989@ubuntu:~$ docker search ubuntu : 查找ubuntu仓库
    NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    ubuntu                                                 Ubuntu is a Debian-based Linux operating sys…   7183                [OK]                
    dorowu/ubuntu-desktop-lxde-vnc                         Ubuntu with openssh-server and NoVNC            159 
    
    yw1989@ubuntu:~$ docker search --filter=stars=100 ubuntu  :查找星级大于100的
    NAME                             DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    ubuntu                           Ubuntu is a Debian-based Linux operating sys…   7183                [OK]                
    dorowu/ubuntu-desktop-lxde-vnc   Ubuntu with openssh-server and NoVNC            159                                     [OK]
    rastasheep/ubuntu-sshd           Dockerized SSH service, built on top of offi…   130     

  • 相关阅读:
    ZOJ 3818 Pretty Poem
    HDU 4597 Play Game
    HDU 4497 GCD and LCM
    CSU 1335 高桥和低桥
    UVA 10791 Minimum Sum LCM
    CSU 1119 Collecting Coins
    CSU 1120 病毒
    UVA 12169 Disgruntled Judge
    HDU 1301 Jungle Roads
    POJ 1258 Agri-Net
  • 原文地址:https://www.cnblogs.com/yaowen/p/8405346.html
Copyright © 2011-2022 走看看