Sometimes we just need to share some files over network to some friends, and need a solution that is easy and fast to setup, provided we already have docker installed in our machine.
First, prepare a directory. Then, put all the files that we want to share inside the directory
$ mkdir files
Then, run a container based on nodejs:slim image, and mount the above directory to our container, which is named "fileshare" in this example
$ docker run -dit -p 8080:80 --name fileshare -v $PWD:/files -w /files node:slim
Install http-server inside the container
$ docker exec -it fileshare npm install -g http-server
Run http-server inside the container
$ docker exec -it fileshare http-server -p 80 .
You should now be able to view your files using a web browser. Just browse to your ip with port 8080 like below
Once you are done, just press control-C on the terminal where the http-server is running, and the http-server will be terminated
No comments:
Post a Comment