magrit icon indicating copy to clipboard operation
magrit copied to clipboard

Installation with docker : Bad Gateway error from nginx server and missing built files in the static folder of magrit app

Open robLittiere opened this issue 2 years ago • 6 comments

Issue Description

Hi, I am encountering a "Bad Gateway" error when trying to access http://localhost:80 after successfully building and launching the containers using Docker Compose. The nginx container is logging the following error message:

2023-06-07 14:42:58 2023/06/07 12:42:58 [error] 7#7: *9 upstream prematurely closed connection while reading response header from upstream, client: 172.20.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.20.0.3:9999/favicon.ico", host: "localhost", referrer: "http://localhost/"

Additionally, the magrit app is logging the following error:

2023-06-07 14:42:58 [2023-06-07 12:42:58 +0000] [9] [ERROR] Unhandled exception
2023-06-07 14:42:58 Traceback (most recent call last):
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 512, in start
2023-06-07 14:42:58     resp, reset = await task
2023-06-07 14:42:58                   ^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 458, in _handle_request
2023-06-07 14:42:58     reset = await self.finish_response(request, resp, start_time)
2023-06-07 14:42:58             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 611, in finish_response
2023-06-07 14:42:58     await prepare_meth(request)
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_fileresponse.py", line 142, in prepare
2023-06-07 14:42:58     st: os.stat_result = await loop.run_in_executor(None, filepath.stat)
2023-06-07 14:42:58                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
2023-06-07 14:42:58     result = self.fn(*self.args, **self.kwargs)
2023-06-07 14:42:58              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/lib/python3.11/pathlib.py", line 1014, in stat
2023-06-07 14:42:58     return os.stat(self, follow_symlinks=follow_symlinks)
2023-06-07 14:42:58            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58 FileNotFoundError: [Errno 2] No such file or directory: 'static/index.html'
2023-06-07 14:42:58 [2023-06-07 12:42:58 +0000] [8] [ERROR] Unhandled exception
2023-06-07 14:42:58 Traceback (most recent call last):
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 512, in start
2023-06-07 14:42:58     resp, reset = await task
2023-06-07 14:42:58                   ^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 458, in _handle_request
2023-06-07 14:42:58     reset = await self.finish_response(request, resp, start_time)
2023-06-07 14:42:58             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_protocol.py", line 611, in finish_response
2023-06-07 14:42:58     await prepare_meth(request)
2023-06-07 14:42:58   File "/usr/local/lib/python3.11/dist-packages/aiohttp/web_fileresponse.py", line 142, in prepare
2023-06-07 14:42:58     st: os.stat_result = await loop.run_in_executor(None, filepath.stat)
2023-06-07 14:42:58                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
2023-06-07 14:42:58     result = self.fn(*self.args, **self.kwargs)
2023-06-07 14:42:58              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58   File "/usr/lib/python3.11/pathlib.py", line 1014, in stat
2023-06-07 14:42:58     return os.stat(self, follow_symlinks=follow_symlinks)
2023-06-07 14:42:58            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-06-07 14:42:58 FileNotFoundError: [Errno 2] No such file or directory: 'static/page404.html'

Investigation

Upon further investigation, I discovered that the static folder of the app does not contain any built files (e.g., HTML, JS) as the server errors point. This absence of built files could be the cause of the issue. Since we copy the folder on the nginx server they are also not in the /var/www/static folder of the nginx container.

Steps to Reproduce

  1. Clone the repository.
  2. Navigate to the project directory (and /misc/Docker directory).
  3. Execute the docker-compose -f docker-compose.yml up -d command.
  4. Access http://localhost:80 in a web browser.
  5. Observe the "Bad Gateway" error and check the logs of the nginx and magrit app containers.

Environment Information

  • Docker version: 4.16.1 (95567)
  • Operating System: Windows 10 + WSL2

Please let me know if you need any further information. Thank you for your assistance 👍

robLittiere avatar Jun 07 '23 13:06 robLittiere

Hi @robLittiere !

Thanks for reporting this issue! It's strange because we're successfully using these Docker recipes for our public server. Anyway, I'll look into it today and get back to you.

mthh avatar Jun 07 '23 13:06 mthh

I just tested on Ubuntu (docker v24.0.2 - docker compose v2.18.1) and it works fine.

I think the problem might be related to the staticfiles volume (https://github.com/riatelab/magrit/blob/master/misc/Docker/docker-compose.yml#L52). Maybe it works slightly differently on Windows, I will investigate.

mthh avatar Jun 07 '23 15:06 mthh

Ok, I haven't had time but I'll investigate further on my windows machine and keep you up to date, especially if I managed to make it work.

I also successfully managed to make the docker recipe work on :

  • Mac M1 - OS Ventura 13.2. Although I encountered some error, I'll try to post another issue since it was a different error, if I manage to consistently recreate it.
  • Ubuntu 22.0.4.2. Worked perfectly

robLittiere avatar Jun 12 '23 10:06 robLittiere

I just installed Magrit using docker-compose (from the docker one-liner in the documentation). I am using a CentOS 9 linux distro.

  • When creating a bind to a local folder to static directory, thus:
volumes:
    - /home/stsinc/dkr/mgt/sta:/home/app/magrit/magrit_app/static

the app fails at launch. That is the case even when I dropped the content of the static folder on GitHub. Possibly an access rights issue?

Otherwise, works fine. Thanks.

asitemade4u avatar Feb 14 '24 19:02 asitemade4u

The link to the documentation is broken.

Indeed, the page links to /docs/ but it should links to /static/book/. I will change the link in the code. In fact I think it only happens when using the single container version of Magrit (such as the image published on the docker hub) because on the public instance (and more broadly when using the 3-container version: Magrit, NGINX and Redis containers) we have a redirection from /docs/ to /static/book/ using NGINX.

mthh avatar Feb 14 '24 21:02 mthh

I've fixed the links to the documentation in 1b086b8 for when Magrit is used in Docker.

mthh avatar Mar 20 '24 19:03 mthh

I'm closing this issue because the new version of the application no longer offers a deployment procedure with Docker and NGINX.

If you have problems with Docker / NGINX on the old version, please reopen an issue (but we offer only limited support on the old version).

mthh avatar Jul 04 '24 18:07 mthh