user7091463
user7091463

Reputation: 167

Docker - Run an HTML file in docker

I want to build a docker container which can run an HTML file on any system by just requiring the user to type docker run.... This is the HTML code:

<!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>

I am currently trying to open the HTML file using an Ubuntu 14.04 environment and using wget to get links2, and then using xdg-open to open the html file. But I'm not getting the page. docker run... just does nothing. No errors, but no webpage either. This is my 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

Any alternatives or correct solutions?

Upvotes: 2

Views: 27417

Answers (2)

arbogastes
arbogastes

Reputation: 1338

Check you docker machine ip with:

docker-machine ip

It will give for example: 192.168.99.100 When your container will be runing then in given IP you can check result (for example http://192.168.99.100/) Place your index.html file in same folder where is your Dockerfile. Your Dockerfile can look like this:

FROM ubuntu:14.04

COPY index.html /var/www/html/

When files will be ready go to their folder and run:

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

And visit http://192.168.99.100/

Upvotes: 2

joshlsullivan
joshlsullivan

Reputation: 1500

You need a service to expose the HTML (apache or nginx). You can simply run $ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx, where some/content links to your HTML file. Here's a link to the official Nginx docker: https://hub.docker.com/_/nginx/

Upvotes: 6

Related Questions