Docker - 运行 docker 中的 HTML 文件

Docker - Run an HTML file in docker

我想构建一个 docker 容器,它可以在任何系统上 运行 一个 HTML 文件,只需要求用户键入 docker run...。 这是 HTML 代码:

<!doctype html>
<html>
  <style>
    body {
      padding: 20px 5%;
      color: white;
      font-family: Sabon, serif;
      margin: auto;
      max-width: 800px;
    }
    @media (min-width: 600px) {
    }
  </style>
  <head>
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <title>D & T</title>
  </head>
  <body>
  <center>   
    <div id="headline">
      <header>
        <h1>Date and Time</h1>
        <p></p>
      </header>
      <div id="blurb">
        <p>This page will show you your current local time.</p> 
      </div>
    </div>
    <div id="section1">
      <h2></h2>
      <p>It is now</p>
    </div>
    <div id="section2">
      <script type="text/javascript">
      document.write ('<p>----<span id="date-time">', new Date().toLocaleString(), '<\/span>----<\/p>')
      if (document.getElementById) onload = function () {
    setInterval ("document.getElementById ('date-time').firstChild.data = new Date().toLocaleString()", 50)
      }
      </script>
    </div>
    <div id="section3">
      <div style="position: absolute; bottom: 5px">
        <i>RG</i>
      </div>
    </div>
    <footer>
      <p><i>Created 26 May 2017</i></p>
    </footer>
  </center>
  </body>
</html>

我目前正在尝试使用 Ubuntu 14.04 环境打开 HTML 文件并使用 wget 获取 links2,然后使用 xdg-open 打开 html 文件。但我没有得到页面。 docker run... 什么都不做。没有错误,但也没有网页。 这是我的 Dockerfile:

FROM ubuntu:14.04

WORKDIR /app

ADD . /app

USER root

RUN apt-get update

RUN apt-get install --no-install-recommends xdg-utils

RUN apt-get install -y --no-install-recommends links2

RUN xdg-open datetime.html

任何替代方案或正确的解决方案?

您需要一个服务来公开 HTML(apache 或 nginx)。您可以简单地 运行 $ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx,其中 some/content link 到您的 HTML 文件。这里有一个link给Nginx官方的docker:https://hub.docker.com/_/nginx/

检查你的 docker 机器 ip:

docker-machine ip

它将给出例如:192.168.99.100 当您的容器将 运行ing 时,您可以在给定的 IP 中检查结果(例如 http://192.168.99.100/) 将 index.html 文件放在与 Dockerfile 相同的文件夹中。您的 Dockerfile 可能如下所示:

FROM ubuntu:14.04

COPY index.html /var/www/html/

当文件准备就绪时转到它们的文件夹并且运行:

docker build -t my_html_file .
docker run -p 80:80 my_html_file

并访问http://192.168.99.100/