|
| 1 | +# |
| 2 | +# nginx-proxy-manager Dockerfile |
| 3 | +# |
| 4 | +# https://github.com/jlesage/docker-nginx-proxy-manager |
| 5 | +# |
| 6 | + |
| 7 | +# Pull base image. |
| 8 | +FROM jlesage/baseimage:alpine-3.8-v2.4.1 |
| 9 | + |
| 10 | +# Define software versions. |
| 11 | +ARG NGINX_PROXY_MANAGER_VERSION=2.0.3 |
| 12 | + |
| 13 | +# Define software download URLs. |
| 14 | +ARG NGINX_PROXY_MANAGER_URL=https://github.com/jc21/nginx-proxy-manager/archive/${NGINX_PROXY_MANAGER_VERSION}.tar.gz |
| 15 | + |
| 16 | +# Define working directory. |
| 17 | +WORKDIR /tmp |
| 18 | + |
| 19 | +# Install dependencies. |
| 20 | +RUN \ |
| 21 | + add-pkg \ |
| 22 | + nodejs \ |
| 23 | + nginx \ |
| 24 | + nginx-mod-stream \ |
| 25 | + mariadb \ |
| 26 | + mariadb-client \ |
| 27 | + certbot \ |
| 28 | + && \ |
| 29 | + # Clean some uneeded stuff from mariadb. |
| 30 | + rm -r \ |
| 31 | + /var/lib/mysql \ |
| 32 | + && \ |
| 33 | + # Clean some uneeded stuff from nginx. |
| 34 | + rm -r \ |
| 35 | + /var/log/nginx \ |
| 36 | + /var/lib/nginx \ |
| 37 | + /var/tmp/nginx \ |
| 38 | + /etc/nginx \ |
| 39 | + /etc/init.d/nginx \ |
| 40 | + /etc/logrotate.d/nginx \ |
| 41 | + /var/www && \ |
| 42 | + ln -s /tmp/nginx /var/tmp/nginx && \ |
| 43 | + # nginx always tries to open /var/lib/nginx/logs/error.log before reading |
| 44 | + # its configuration. Make sure it exists. |
| 45 | + mkdir -p /var/lib/nginx/logs && \ |
| 46 | + ln -sf /config/log/nginx/error.log /var/lib/nginx/logs/error.log |
| 47 | + |
| 48 | +# Install Nginx Proxy Manager. |
| 49 | +RUN \ |
| 50 | + # Install packages needed by the build. |
| 51 | + add-pkg --virtual build-dependencies \ |
| 52 | + build-base \ |
| 53 | + curl \ |
| 54 | + yarn \ |
| 55 | + git \ |
| 56 | + python \ |
| 57 | + npm \ |
| 58 | + bash \ |
| 59 | + && \ |
| 60 | + |
| 61 | + # Install node-prune. |
| 62 | + echo "Installing node-prune..." && \ |
| 63 | + curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /tmp/bin && \ |
| 64 | + |
| 65 | + # Download the Nginx Proxy Manager package. |
| 66 | + echo "Downloading Nginx Proxy Manager package..." && \ |
| 67 | + mkdir nginx-proxy-manager && \ |
| 68 | + curl -# -L ${NGINX_PROXY_MANAGER_URL} | tar xz --strip 1 -C nginx-proxy-manager && \ |
| 69 | + |
| 70 | + # Build Nginx Proxy Manager. |
| 71 | + echo "Building Nginx Proxy Manager..." && \ |
| 72 | + cp -r nginx-proxy-manager /app && \ |
| 73 | + cd /app && \ |
| 74 | + yarn install && \ |
| 75 | + npm --cache /tmp/.npm run-script build && \ |
| 76 | + rm -rf node_modules && \ |
| 77 | + yarn install --prod && \ |
| 78 | + /tmp/bin/node-prune && \ |
| 79 | + cd /tmp && \ |
| 80 | + |
| 81 | + # Install Nginx Proxy Manager. |
| 82 | + echo "Installing Nginx Proxy Manager..." && \ |
| 83 | + mkdir -p /opt/nginx-proxy-manager/src && \ |
| 84 | + cp -r /app/dist /opt/nginx-proxy-manager/ && \ |
| 85 | + cp -r /app/node_modules /opt/nginx-proxy-manager/ && \ |
| 86 | + cp -r /app/src/backend /opt/nginx-proxy-manager/src/ && \ |
| 87 | + cp -r /app/package.json /opt/nginx-proxy-manager/ && \ |
| 88 | + cp -r /app/knexfile.js /opt/nginx-proxy-manager/ && \ |
| 89 | + cp -r nginx-proxy-manager/rootfs/etc/nginx /etc/ && \ |
| 90 | + cp -r nginx-proxy-manager/rootfs/var/www /var/ && \ |
| 91 | + |
| 92 | + # Change the management interface port to the unprivileged port 8181. |
| 93 | + sed-patch 's|81|8181|' /opt/nginx-proxy-manager/src/backend/index.js && \ |
| 94 | + sed-patch 's|81|8181|' /etc/nginx/conf.d/default.conf && \ |
| 95 | + |
| 96 | + # Change the HTTP port 80 to the unprivileged port 8080. |
| 97 | + sed-patch 's|listen 80 |listen 8080 |' /etc/nginx/conf.d/default.conf && \ |
| 98 | + sed-patch 's|listen 80;|listen 8080;|' /opt/nginx-proxy-manager/src/backend/templates/letsencrypt-request.conf && \ |
| 99 | + sed-patch 's|listen 80;|listen 8080;|' /opt/nginx-proxy-manager/src/backend/templates/_listen.conf && \ |
| 100 | + |
| 101 | + # Change the HTTPs port 443 to the unprivileged port 4443. |
| 102 | + sed-patch 's|listen 443 |listen 4443 |' /opt/nginx-proxy-manager/src/backend/templates/_listen.conf && \ |
| 103 | + |
| 104 | + # Fix nginx test command line. |
| 105 | + sed-patch 's|-g "error_log off;"||' /opt/nginx-proxy-manager/src/backend/internal/nginx.js && \ |
| 106 | + |
| 107 | + # Make sure nginx runs under the proper user. |
| 108 | + #sed-patch 's|user root;|user app;|' /etc/nginx/nginx.conf && \ |
| 109 | + |
| 110 | + # Remove the `user` directive, since we want nginx to run as non-root. |
| 111 | + sed-patch 's|user root;|#user root;|' /etc/nginx/nginx.conf && \ |
| 112 | + |
| 113 | + # Make sure nginx loads the stream module. |
| 114 | + sed-patch '/daemon off;/a load_module /usr/lib/nginx/modules/ngx_stream_module.so;' /etc/nginx/nginx.conf && \ |
| 115 | + |
| 116 | + # Adjust paths. |
| 117 | +# sed-patch 's|/data/|/config/|' /etc/nginx/nginx.conf && \ |
| 118 | +# sed-patch 's|/data/|/config/|' /etc/nginx/conf.d/default.conf && \ |
| 119 | +# sed-patch 's|/data/|/config/|' /opt/nginx-proxy-manager/src/backend/templates/proxy_host.conf && \ |
| 120 | +# sed-patch 's|/logs/|/log/|' /etc/nginx/nginx.conf && \ |
| 121 | +# sed-patch 's|/logs/|/log/|' /etc/nginx/conf.d/default.conf && \ |
| 122 | +# sed-patch 's|/logs/|/log/|' /opt/nginx-proxy-manager/src/backend/templates/proxy_host.conf && \ |
| 123 | + |
| 124 | + # Adjust the nginx proxy cache path. |
| 125 | +# sed-patch 's|/var/lib/nginx/cache/|/config/nginx/cache/|' /etc/nginx/nginx.conf && \ |
| 126 | + |
| 127 | + |
| 128 | + # Redirect `/data' to '/config'. |
| 129 | + ln -s /config /data && \ |
| 130 | + |
| 131 | + # Make sure nginx cache is stored on the persistent volume. |
| 132 | + ln -s /config/nginx/cache /var/lib/nginx/cache && \ |
| 133 | + |
| 134 | + # Make sure the manager config file is stored in persistent volume. |
| 135 | + mkdir /opt/nginx-proxy-manager/config && \ |
| 136 | + ln -s /config/production.json /opt/nginx-proxy-manager/config/production.json && \ |
| 137 | + |
| 138 | + # Make sure letencrypt certificates are stored in persistent volume. |
| 139 | + ln -s /config/letsencrypt /etc/letsencrypt && \ |
| 140 | + |
| 141 | + # Cleanup. |
| 142 | + del-pkg build-dependencies && \ |
| 143 | + rm -r \ |
| 144 | + /app \ |
| 145 | + /usr/lib/node_modules \ |
| 146 | + /opt/nginx-proxy-manager/node_modules/bcrypt/build \ |
| 147 | + && \ |
| 148 | + rm -rf /tmp/* /tmp/.[!.]* |
| 149 | + |
| 150 | +# Add files. |
| 151 | +COPY rootfs/ / |
| 152 | + |
| 153 | +# Set environment variables. |
| 154 | +ENV APP_NAME="Nginx Proxy Manager" \ |
| 155 | + KEEP_APP_RUNNING=1 |
| 156 | + |
| 157 | +# Define mountable directories. |
| 158 | +VOLUME ["/config"] |
| 159 | + |
| 160 | +# Expose ports. |
| 161 | +# - 8080: HTTP traffic |
| 162 | +# - 4443: HTTPs traffic |
| 163 | +# - 8181: Management web interface |
| 164 | +EXPOSE 8080 4443 8181 |
| 165 | + |
| 166 | +# Metadata. |
| 167 | +LABEL \ |
| 168 | + org.label-schema.name="nginx-proxy-manager" \ |
| 169 | + org.label-schema.description="Docker container for Nginx Proxy Manager" \ |
| 170 | + org.label-schema.version="unknown" \ |
| 171 | + org.label-schema.vcs-url="https://github.com/jlesage/docker-nginx-proxy-manager" \ |
| 172 | + org.label-schema.schema-version="1.0" |
0 commit comments