docker创建nginx容器

创建nginx容器

需要同时提供配置文件和网页文件
实例:

[root@localhost ~]# docker run -it --name  html -v /var/www/html/:/usr/share/nginx/html busybox
/ # exit
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE        COMMAND               CREATED          STATUS                       PORTS                               NAMES
f1432947c621   busybox      "sh"                  23 seconds ago   Exited (0) 14 seconds ago                                        html
3037202498fe   httpd:v1.0   "/scripts/start.sh"   17 hours ago     Exited (255) 3 minutes ago   0.0.0.0:80->80/tcp, :::80->80/tcp   httpd
5797953ad449   centos       "/bin/bash"           21 hours ago     Exited (255) 18 hours ago                                        centos

安装nginx并提供测试的配置文件
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# mkdir /config
[root@localhost ~]# cp -r /etc/nginx/* /config/
[root@localhost ~]# ls /config/
conf.d                  koi-utf             scgi_params
default.d               koi-win             scgi_params.default
fastcgi.conf            mime.types          uwsgi_params
fastcgi.conf.default    mime.types.default  uwsgi_params.default
fastcgi_params          nginx.conf          win-utf
fastcgi_params.default  nginx.conf.default

基于容器html的容器卷挂载数据卷
[root@localhost ~]# docker run --name nginx_conf --volumes-from html   -v /config:/etc/nginx busybox
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE        COMMAND               CREATED              STATUS                       PORTS                               NAMES
7015c9be3ee1   busybox      "sh"                  9 seconds ago        Exited (0) 7 seconds ago                                         nginx_conf
f1432947c621   busybox      "sh"                  About a minute ago   Exited (0) 58 seconds ago                                        html
3037202498fe   httpd:v1.0   "/scripts/start.sh"   17 hours ago         Exited (255) 3 minutes ago   0.0.0.0:80->80/tcp, :::80->80/tcp   httpd
5797953ad449   centos       "/bin/bash"           22 hours ago         Exited (255) 18 hours ago                                        centos

基于容器nginx_conf的容器卷,创建nginx容器
[root@localhost ~]# docker run --name nginx -dit -p 80:80 --volumes-from nginx_conf nginx
c9819c1ffe6614ce322d46ff567fbfd2edce09e6f27418956456d7d804184755

[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
c9819c1ffe66   nginx     "/docker-entrypoint.…"   8 seconds ago   Up 7 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

查看一下
[root@localhost ~]# docker exec -it nginx /bin/bash
root@c9819c1ffe66:/# ls /etc/nginx/
conf.d                  koi-utf             scgi_params
default.d               koi-win             scgi_params.default
fastcgi.conf            mime.types          uwsgi_params
fastcgi.conf.default    mime.types.default  uwsgi_params.default
fastcgi_params          nginx.conf          win-utf
fastcgi_params.default  nginx.conf.default

编写网页文件,随便放一个网站
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# ls
[root@localhost html]# cat index.html 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>别踩白块</title>
    <link rel="stylesheet" href="css/index.css" />
    <script src="js/index.js" type="text/javascript"></script>
  </head>
  <body>
    <h2>score</h2>
    <h2 id="score">0</h2>
    <div id="main">
      <div id="con"></div>
    </div>
    <div class="btn">
      <button class="start" onclick="start()">
        开始游戏
      </button>
    </div>
  </body>

去容器查看一下
root@c9819c1ffe66:/# ls /usr/share/nginx/html/
'(15'$'\346\235\241\346\266\210\346\201\257'') '$'\351\203\250\347\275\262\344\270\252\347\275\221\347\253\231''_'$'\346\227\251\345\267\235\350\257\255\347\232\204\345\215\232\345\256\242''-CSDN'$'\345\215\232\345\256\242''.html'
 123
 index.html

root@c9819c1ffe66:/# ls /usr/share/nginx/html/
css  index.html  js

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值