Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 2.13 KB

README.md

File metadata and controls

60 lines (42 loc) · 2.13 KB

simple-http-server

I get asked, "how can I serve the files I have locally?" A ready answer to this is to use Python's SimpleHTTPServer (now with Python 3, this is http.server). This question, however, is often from individuals who will have Docker installed but don't necessarily want to dig into the details of specific python versions or writing a Dockerfile. The goal of this project is to give a single command with no extra dependencies that will serve the directory you point it at.

WARNING: DO NOT run this in production. This is purely a convenience tool.

Using

To serve files, stand the server up with this docker command. Make sure you map (as a volume with /serve) the directory you wish to serve:

docker run --rm \
    -v <directory-to-serve>:/serve \
    -p 80:8000 \
    jdkelley/simple-http-server:latest

To serve your current directory, use:

docker run --rm \
    -v $(pwd):/serve \
    -p 80:8000 \
    jdkelley/simple-http-server:latest

I find it useful to add a bash function to my profile to avoid typing that all out:

simple-http-server() {
    docker run --rm \
        -v $(pwd):/serve \
        -p 80:8000 \
        jdkelley/simple-http-server:latest
}

And then use it with simple-http-server. You can find an example of the function I use in example/bash_functions.sh.

Building from source

docker build -t http-server:latest .

To run this generated image and serve your current directory, run docker run $(pwd):/serve -p 80:8000 http-server:latest.

Deployed

This is deployed on GitHub Package Registry and Docker Hub.

The source can be found on GitHub.