2017-05-27 99 views
-1

我想要构建一个docker容器,它可以在任何系统上运行HTML文件,只需要用户键入docker run...即可。 这是HTML代码:Docker - 在docker中运行一个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的环境和使用wget得到links2,然后使用XDG-开开HTML文件打开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 

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

+1

“运行HTML文件” - 你什么意思?你想在浏览器中显示这个html或什么? – arbogastes

+0

是的,在浏览器中。它甚至有可能吗? – user7091463

回答

0

你需要一个服务来暴露HTML(apache或nginx)。您只需运行$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx,其中some/content链接到您的HTML文件。这里有一个链接到官方的Nginx泊坞窗:https://hub.docker.com/_/nginx/

+0

我遵循官方的Nginx docker说明,但是在执行'docker run --name xyz -d -p 8080:80 abc'后,我得到一个像这样的长字符串:'8ezsh23dfg4fgh23 ...'这是什么和什么它的意思是? – user7091463

0

检查你泊坞窗机的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/

+0

如何“访问”IP?在哪里,我在哪里输入它?我做了上面的,但是在执行'docker run -p 80:80 my_html_file'后,我什么都没有。只是一个新的命令行。 – user7091463

+0

@ user7091463打开您的浏览器并将您的地址粘贴到它以显示您的HTML。 – arbogastes