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
2712632a69b3   busybox   "sh"      9 seconds ago   Exited (0) 4 seconds ago             html
安装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
4ff42fcb86c6   busybox   "sh"      33 seconds ago   Exited (0) 31 seconds ago             nginx_conf
2712632a69b3   busybox   "sh"      2 minutes ago    Exited (0) 2 minutes ago              html

基于容器nginx_conf的容器卷,创建nginx容器
[root@localhost ~]# docker run --name nginx -dit -p 80:80 --volumes-from nginx_conf nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
e5ae68f74026: Pull complete 
21e0df283cd6: Pull complete 
ed835de16acd: Pull complete 
881ff011f1c9: Pull complete 
77700c52c969: Pull complete 
44be98c0fab6: Pull complete 
Digest: sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
Status: Downloaded newer image for nginx:latest
ec7873759bf89814e2a253a5cc1b812090aa6db134f208101061a6828edd1d63
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
ec7873759bf8   nginx     "/docker-entrypoint.…"   16 seconds ago   Up 13 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

查看一下
[root@localhost ~]# docker exec -it nginx /bin/bash
root@ec7873759bf8:/# 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
css  index.html  js
[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@ec7873759bf8:/# 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、付费专栏及课程。

余额充值