There are similar questions in SO but not for this specific problem.
Tools: docker-compose 1.21.2; symfony 3.4; nginx 1.10.3
I have several decoupled containers ("Each container should have only one concern"). Everything works except for getting the assets of the symfony (3.4) application in the browser. The defined routes work, templates are rendered correctly, only assets are the problem. Besides using the same setup but serving in a dev machine locally (without containers) there are no problems.
With volumes it worked but I want to have them at production so as the docs indicate https://docs.docker.com/compose/production/#modify-your-compose-file-for-production a change you may need:
- Removing any volume bindings for application code, so that code stays inside the container and can’t be changed from outside
Facts:
- Inside the nginx container logs report 404 accesses but no errors.
- Inside the php-symfony container the prod logs show lines like
request.ERROR: Uncaught .... NotFoundException for "GET /css/main.css" at ...RouterListener.php {"exception": ".../NotFoundHttpException(code: 0) ... ResourceNotFoundException"} []
- Checking dev in a browser
http://<host>:<port>/app_dev.php/css/main.css
nginx return 404. (I made dev environment available externally) - Checking dev in a browser for the route, example
http://<host>:<port>/app_dev.php/css
appears the Symfony Exception page No route found for "GET /css" with the same informationResourceNotFoundException > NotFoundHttpException
- Modifying access permissions to the
web
folder in the containerchmod -R a+rwx .../web
does not make a difference.
Relevant section docker-compose.yml
version: "2"
services:
site:
...
working_dir:
/var/www/html/site
site_webserver:
...
ports:
- <port>:80
depends_on:
- site
links:
- site
Relevant section nginx.conf
server {
listen 80;
server_name "";
root /var/www/html/site/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^.*/(app_dev|config)\.php(/|$) {
fastcgi_pass lockate_site:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
}
}