Sometimes you just need the simplest possible example of a static website running inside a Docker container in order to demo something.
How do you create a simple static HTML site in a Docker container? Like this:
Create a simple static website.
Create a folder named ‘src’ somewhere on your drive. Then add a file called ‘index.html’ and add the following text to your file, then save the file.
html
<p>Hello world</p>
Create the Dockerfile
Inside the src folder add a file named ‘Dockerfile’ with no extension. Add the following text to your file.
FROM nginx
COPY . /usr/share/nginx/html
Save this as Dockerfile
Build your Container
docker build -t hello-world .
Run this command to build a container from your Dockerfile.
The above command will build your docker container using the Dockerfile in the same folder, and it will create with the name and tag of ‘hello-world:latest’.
Run your Container
docker run -it -d -p 8080:80 hello-world
Now you run your container with the above command.
The above command will run the ‘hello-world:latest’ container.
Load your web page
Now you should be able to load your website at http://localhost:8080/index.html.

Leave a comment