Skip to content

Share files with nginx and Docker

When you need to share files fast and with no restrictions then nginx and docker are your best friend. Simply pull the Docker image, set your config and run it all with docker-compose. So lets get started.

If you are more a visual person, then i have you covered. Take a look at my video on this topic.



So software is straight forward enough. You need to have a modern Linux Operating system like ubuntu or ArchLinux.


with Docker installed. To install Docker on Ubuntu simply run the following command.

sudo apt update
sudo apt install

For Archlinux, take a look at my guide on how to install docker on archlinux.

Docker Compose

Docker Compose is a python tool for managing Docker services in a single file. It should be installed via pip.

First make sure pip is installed

sudo apt install python3-pip

Then install docker compose

pip install docker-compose

After using pip docker-compose will not be in your PATH, so you can add it by running the following.

echo "export PATH=$PATH:/home/$USER/.local/bin" >> /home/$USER/.bashrc

Correct User Permissions

the user we are using needs to be part of the docker user group.

sudo usermod -aG docker $USER

Now you either need to logout and log back in, or reboot to activate the user group.

Set up Docker Compose file

Once docker is install we need to select an image to use. I will pick a nginx image based on alpine linux so that is as small as possible.

nginx config file

We will need a cusomized nginx config file so we can auto display the file system contents.

In the same directory as our nginx file we find default.conf with our config.

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        autoindex on;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;

    # proxy the PHP scripts to Apache listening on
    #location ~ \.php$ {
    #    proxy_pass;

    # pass the PHP scripts to FastCGI server listening on
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #    deny  all;

“autoindex on” is the important part.

Docker Compose file

Inside the docker compose file you will find the following.

version: '3'
    image: nginx:stable-alpine-slim
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro
      - /nfs/:/usr/share/nginx/html:ro 
      - 80:80

Where you see “/nfs” is where you put the file system you want to share.

Start is all up.

Start is all up with docker compose command.


If you get any 403 “Permission Denied” errors then its likely to be an issue with the folder permissions. Just make sure the folder is readable by the user you are running the docker image as.

docker-compose -d up

Now using your favourite browser just go to the ip address of the system you ran docker on to see the files.


Be sure to stop this thing or add some security when you are done. Its not very secure.

Wrap Up

Some times we just need to share a file the fast way. In this write up i explain how to Share files with nginx and Docker. Docker compose is really powerful and requires a deeper tutorial. But this should get you up and running.

Published inDockerLinux