From 8019cd72402e8f4e4d4437bb7dddb3e58fad675d Mon Sep 17 00:00:00 2001 From: Berger Adrian Date: Fri, 1 Apr 2022 10:38:31 +0200 Subject: [PATCH 1/2] Run container unprivileged --- Dockerfile | 6 +++--- README.md | 4 ++-- default.conf | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 891a7e4..65f9945 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM nginx:alpine +FROM nginxinc/nginx-unprivileged:stable-alpine -MAINTAINER Mohammad Naghavi +LABEL author="Mohammad Naghavi " ADD default.conf /etc/nginx/conf.d/default.conf ADD css/ /opt/www/file-browser/css/ @@ -9,4 +9,4 @@ ADD js/ /opt/www/file-browser/js/ ADD index.html /opt/www/file-browser/ VOLUME /opt/www/files/ -EXPOSE 80 \ No newline at end of file +EXPOSE 8080 \ No newline at end of file diff --git a/README.md b/README.md index 9d9bb68..c0ecd1c 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ A sample nginx configuration is also included which mounts **file browser** unde Mainly for demonstration purposes a docker image is also available [here](https://hub.docker.com/r/mohamnag/nginx-file-browser/). In order to use this docker image, the volume which has to be served should -be mounted under `/opt/www/files/` and port `80` of container shall be mapped +be mounted under `/opt/www/files/` and port `8080` of container shall be mapped to a proper port on host. A proper run would look like: ``` -$ docker run -p 8080:80 -v /path/to/my/files/:/opt/www/files/ mohamnag/nginx-file-browser +$ docker run -p 8080:8080 -v /path/to/my/files/:/opt/www/files/ mohamnag/nginx-file-browser ``` With container up and running you can point your browser to IP of docker host with given port to view the files. For example with above run command assuming docker host having IP with `192.168.0.200` we have to navigate to this URL: diff --git a/default.conf b/default.conf index 3efc137..6600917 100644 --- a/default.conf +++ b/default.conf @@ -1,5 +1,5 @@ server { - listen 80; + listen 8080; server_name localhost; root /opt/www/; From 6e7c4e274a6e65ef306b2a54c1626f63bac58cbc Mon Sep 17 00:00:00 2001 From: Berger Adrian Date: Fri, 8 Apr 2022 13:51:48 +0200 Subject: [PATCH 2/2] Add 2 image variants (root & rootless) --- Dockerfile | 4 ++-- Dockerfile-rootless | 12 ++++++++++++ README.md | 7 ++++++- default-rootless.conf | 26 ++++++++++++++++++++++++++ default.conf | 2 +- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Dockerfile-rootless create mode 100644 default-rootless.conf diff --git a/Dockerfile b/Dockerfile index 65f9945..778ba33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM nginxinc/nginx-unprivileged:stable-alpine +FROM nginx:alpine LABEL author="Mohammad Naghavi " @@ -9,4 +9,4 @@ ADD js/ /opt/www/file-browser/js/ ADD index.html /opt/www/file-browser/ VOLUME /opt/www/files/ -EXPOSE 8080 \ No newline at end of file +EXPOSE 80 \ No newline at end of file diff --git a/Dockerfile-rootless b/Dockerfile-rootless new file mode 100644 index 0000000..7125a50 --- /dev/null +++ b/Dockerfile-rootless @@ -0,0 +1,12 @@ +FROM nginxinc/nginx-unprivileged:stable-alpine + +LABEL author="Mohammad Naghavi " + +ADD default-rootless.conf /etc/nginx/conf.d/default.conf +ADD css/ /opt/www/file-browser/css/ +ADD image/ /opt/www/file-browser/image/ +ADD js/ /opt/www/file-browser/js/ +ADD index.html /opt/www/file-browser/ + +VOLUME /opt/www/files/ +EXPOSE 8080 \ No newline at end of file diff --git a/README.md b/README.md index c0ecd1c..e72a4f7 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,14 @@ A sample nginx configuration is also included which mounts **file browser** unde Mainly for demonstration purposes a docker image is also available [here](https://hub.docker.com/r/mohamnag/nginx-file-browser/). In order to use this docker image, the volume which has to be served should -be mounted under `/opt/www/files/` and port `8080` of container shall be mapped +be mounted under `/opt/www/files/` and port `80` (root) or `8080` (rootless)) of container shall be mapped to a proper port on host. A proper run would look like: +root +``` +$ docker run -p 8080:80 -v /path/to/my/files/:/opt/www/files/ mohamnag/nginx-file-browser +``` +rootless: ``` $ docker run -p 8080:8080 -v /path/to/my/files/:/opt/www/files/ mohamnag/nginx-file-browser ``` diff --git a/default-rootless.conf b/default-rootless.conf new file mode 100644 index 0000000..6600917 --- /dev/null +++ b/default-rootless.conf @@ -0,0 +1,26 @@ +server { + listen 8080; + server_name localhost; + + root /opt/www/; + index index.html index.htm; + + location /files/ { + alias /opt/www/files/; + index ___i; # we really need no index here, just listing files + + autoindex on; + autoindex_format json; + disable_symlinks off; + } + + location / { + root /opt/www/file-browser/; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + +} \ No newline at end of file diff --git a/default.conf b/default.conf index 6600917..3efc137 100644 --- a/default.conf +++ b/default.conf @@ -1,5 +1,5 @@ server { - listen 8080; + listen 80; server_name localhost; root /opt/www/;