Create a webserver in a few seconds

Andrew Wong
2 min readJul 14, 2021

And in a single command line, using the magic of Docker

Today morning I needed to share a big file (Microsoft Office ISO in case you are wondering) over the local network with my brother.

I have this ISO file on my hard drive. I’m running Linux and he’s running Windows.

There are of course many ways to share the file. I could upload it to S3 or a Dropbox and share him the link. But doing the above options requires the file to be transferred over the Internet twice. Not very efficient.

What if I could whip up a quick webserver on my PC, share the link from my hard drive, and have him download it directly? I can then terminate the webserver once he is done; I don’t need to have a webserver installation hanging around my system, potentially posing a security risk?

It turn out that I could, with the magic of Docker.

You can easily do it too. If you use Ubuntu and don’t have Docker installed, run this command first to install it:

sudo apt-get install docker.io

After installing Docker, assuming that the file is in this location:

/home/user/Downloads/Office.iso

You can then run this command to whip up an NGINX container:

docker run --rm --name tmp-nginx-container -v /home/user/Downloads:/usr/share/nginx/html:ro -p 80:80 -d nginx

Replace the part in bold, with the directory where the file is located.

The content will then be available in this location:

http://<your IP address>/Office.iso

After you are done, stop and remove the container (or if you forget, the container will be stopped the next time you rebooted).

docker stop tmp-nginx-container

The webserver will be torn down, leaving almost no trace of it on your system.

Well, almost, because the downloaded Docker images are still in your system. In case you need to run the Webserver again, the container will start immediately without downloading anything.

If you also wanted to remove those images, run:

docker system prune

And your system will be none the wiser!

--

--