This week end, I needed to share a folder of my personal server to my family. There is a really simple way to do this using docker ! Let’s see it !
I will use the docker capacity to associate physical volumes to a specific container.
The -v flag
Checking the official Docker documentation, the “-v” flag “consists of three fields, separated by colon characters (:
). The fields must be in the correct order, and the meaning of each field is not immediately obvious.
- In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.
- The second field is the path where the file or directory are mounted in the container.
- The third field is optional, and is a comma-separated list of options, such as
ro
.”
The apache container
Docker allow to deploy a http server easily using the “httpd” container ( https://hub.docker.com/_/httpd). This container will run on my server, used to share my specific folder.
Pulling the image
docker pull httpd
This command will add the “httpd” image to my docker available images.
Running the container
docker run --detach --name=simple-share -v /path/to/shared/directory:/usr/local/apache2/htdocs/my/specific/shared/directory -p incoming-port:80 httpd:latest
This command will:
- Run the container, naming it “simple-share”
- Mount the “/path/to/shared/directory” to “/usr/local/apache2/htdocs/my/specific/shared/directory”
- Redirect all requests on my server, using the “incoming-port”, to the http port
Using the http://my-server-ip-or-dns:incoming-port/my/specific/shared/directory, my family was able to access the shared content!