Sometimes you just need to serve a folder over http immediately!

Here are some quick one-liners to start a temporary webserver.

All of the following examples serve pwd, so make sure you cd ~/the-folder-you-wish-to-share first.

Use docker apache httpd:alpine

This will automatically generate directory listings, also the httpd:alpine image is actually much smaller than the nginx image. Docker will automatically expose the ports through UFW firewall while the container is running. Overall this is the winning one-liner to run a quick http server.

docker run -it --rm -p 8080:80 -v ./:/usr/share/nginx/html nginx:alpine
Use python3

This will also automatically generate directory listings. Note this will not automatically expose the port in the firewall, so for instance if running UFW you can open the port (permanently beware!) like so: sudo ufw allow 8080/tcp. For this reason, docker methods are preferable as they automatically expose the port only for the life of the container.

python3 -m http.server 8080
Use docker nginx:alpine

I prefer nginx in general, but this will NOT generate directory listings. It will automatically serve index.html if it exists, but even without directory listings, you can download things as long as you specify exact filenames in your URLs.

docker run -it --rm -p 8080:80 -v ./:/usr/share/nginx/html nginx:alpine

You can now load it up in your browser http://localhost:8080

Press CTRL+C to kill the process.

Next Post Previous Post