【问题标题】:Docker - Run an HTML file in dockerDocker - 在 docker 中运行 HTML 文件
【发布时间】:2017-10-28 09:41:35
【问题描述】:

我想构建一个 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 文件”——你是什么意思?你想在浏览器中显示这个 html 还是什么?
  • 是的,在浏览器中。有可能吗?

标签: html ubuntu docker dockerfile docker-container


【解决方案1】:

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

【讨论】:

  • 我按照官方 Nginx docker 说明进行操作,但是在执行docker run --name xyz -d -p 8080:80 abc 之后,我只得到一个长字符串,如下所示:8ezsh23dfg4fgh23... 它是什么,是什么意思?
【解决方案2】:

检查你的 docker 机器 ip:

docker-machine ip

它将给出例如:192.168.99.100 当您的容器将运行时,您可以在给定的 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/

【讨论】:

  • 如何“访问”IP?如,我到底在哪里输入它?我做了上面的,但是在做了docker run -p 80:80 my_html_file之后,我什么也没得到。只是一个新的命令行。
  • @user7091463 打开您的浏览器并将您的地址 ip 粘贴到其中以显示您的 html。
猜你喜欢
  • 2020-07-01
  • 1970-01-01
  • 2017-10-03
  • 1970-01-01
  • 2023-03-12
  • 2021-10-03
  • 1970-01-01
  • 2016-05-05
  • 2020-04-22
相关资源
最近更新 更多