[英]How to protect a web application running in a Docker container by username and password?
I have written a Node.js web application that gets packaged as a Docker image.我编写了一个打包为 Docker 映像的 Node.js Web 应用程序。 I can run this image, and everything is perfectly fine.
我可以运行这个图像,一切都很好。
Now I would like to show the web application so someone else, so I would like to run the Docker image on a server on the internet - but I do not want it to be publicly available to everyone.现在我想向其他人展示这个 Web 应用程序,所以我想在 Internet 上的服务器上运行 Docker 映像——但我不希望它对所有人公开可用。 As a minimal level of protection I'd like to add that you need to enter your username and password - without the need to change the web application or its Docker image<\/strong> .
作为最低级别的保护,我想补充一点,您需要输入用户名和密码——无需更改 Web 应用程序或其 Docker 映像<\/strong>。
How could I do this?我怎么能这样做?
One option I can think of is not to expose the Docker image at all to the public, but have a second image using eg Nginx, which then uses the Node.js image as upstream, but handles authentication before passing through.我能想到的一种选择是根本不向公众公开 Docker 映像,而是使用例如 Nginx 使用第二个映像,然后使用 Node.js 映像作为上游,但在通过之前处理身份验证。
Does this sound reasonable, or is there an easier way?这听起来合理吗,还是有更简单的方法?
NGINX can add HTTP basic authentication, so it should work. NGINX可以添加HTTP基本身份验证,因此它应该可以工作。
http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
这里给出了一个现成的例子: https ://github.com/beevelop/docker-nginx-basic-auth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.