Nginx Alias Is Giving 'File not found' with Docker-Compose Containers - php

I have two Laravel projects
Laravel 4 with 664 user:www-data permission
Laravel 5 with 664 user:www-data permission
Note: moduletwo is the alias being used in this virtual host to point to the Laravel 5 files.
I am trying to configure both on my local machine where the Laravel 4 is the main project and Laravel 5 will be used as an alias in Nginx virtual host.
Laravel 4 is working good and no issue with that.
But when I try to access the Laravel 5 module it says File not found.and here are the logs:
access.log:
GET `/moduletwo/index.php/LFiveRoute HTTP/1.1" 404 27 "http://www.Laravel.dev/LFourRoute`
error.log:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.22.0.1, server: www.Laravel.dev, request: "GET /moduletwo/index.php/LFiveRoute HTTP/1.1", upstream: "fastcgi://172.22.0.5:9000", host: "www.Laravel.dev", referrer: "http://www.Laravel.dev/LFourRoute
script.log:
/var/www/Laravel4/public/moduletwo/index.php > GET /moduletwo/index.php/LFiveRoute HTTP/1.1
Processes in Nginx Container
Nginx master/worker processes
ps -ef | grep 'nginx'
root 1 0 0 06:15 ? 00:00:00 nginx: master process nginx -g daemon off;
www-data 7 1 0 06:16 ? 00:00:00 nginx: worker process
root 19 8 0 07:45 ? 00:00:00 grep nginx
fpm Processes
ps -ef | grep 'fpm'
root 21 8 0 07:47 ? 00:00:00 grep fpm
Processes in PHP71 Container
Nginx master/worker processes
none
fpm Processes
ps -ef | grep fpm
root 1 0 0 06:15 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
www-data 8 1 0 06:16 ? 00:00:01 php-fpm: pool www
www-data 9 1 0 06:17 ? 00:00:01 php-fpm: pool www
www-data 10 1 0 06:22 ? 00:00:01 php-fpm: pool www
root 22 13 0 07:49 ? 00:00:00 grep fpm
Docker Compose File:
version: '2'
services:
nginx:
container_name:
Laravel-nginx
restart: always
build:
context: ./
dockerfile: deploy/web.docker
volumes:
- ./:/var/www/Laravel4
- ./../Laravel_5:/var/www/Laravel5
- ./app/storage/logs/nginx:/var/log/nginx
ports:
- "80:80"
links:
- php71
networks:
Laravel_net:
ipv4_address: 172.22.0.2
database:
container_name:
Laravel-db
restart: always
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_ROOT_USER=root"
- "MYSQL_DATABASE=laravel_4"
ports:
- "3309:3306"
networks:
Laravel_net:
ipv4_address: 172.22.0.3
redis:
container_name:
Laravel-redis
image: redis:3.2
ports:
- "6372:6379"
networks:
Laravel_net:
ipv4_address: 172.22.0.4
php71:
container_name:
Laravel-php-71
restart: always
build:
context: ./
dockerfile: deploy/app.docker
volumes:
- ./:/var/www/Laravel4
- ./../Laravel_5:/var/www/Laravel5
links:
- database
- redis
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
networks:
Laravel_net:
ipv4_address: 172.22.0.5
networks:
Laravel_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.22.0.0/16
gateway: 172.22.0.1
web.docker file:
FROM nginx:1.10
EXPOSE 80
EXPOSE 443
ADD ./deploy/vhost.conf /etc/nginx/conf.d/default.conf
ADD ./deploy/nginx.conf /etc/nginx/nginx.conf
WORKDIR /var/www
app.docker file:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
nginx.conf file
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log warn;
events {
# A single worker process can handle 1024 connections
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
log_format scripts '$document_root$fastcgi_script_name > $request';
access_log /var/log/nginx/scripts.log scripts;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
}
vhost.conf file:
server {
listen 80;
server_name www.laravel.dev;
charset utf-8;
sendfile off;
client_max_body_size 100m;
index index.php;
root /var/www/Laravel4/public;
location ~ ^/moduletwo/(.+(?:css|js|woff|woff2|ttf))$ {
include fastcgi_params;
alias /var/www/Laravel5/public/$1;
#access_log off;
}
#moduletwo code in laravel5
location /moduletwo/ {
include fastcgi_params;
alias /var/www/Laravel5/public;
## Check for file existing and if there, stop ##
if (-f $request_filename) {
break;
}
## Check for file existing and if there, stop ##
if (-d $request_filename) {
break;
}
index index.php;
try_files $uri $uri/ #moduletwo;
# try_files $uri $uri/ /index.php?$query_string;
}
location #moduletwo {
include fastcgi_params;
rewrite /moduletwo/(.*)$ /moduletwo/index.php?/$1 last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php71:9000;
fastcgi_index index.php;
set $php_root /var/www/Laravel4/public;
if ($request_uri ~ /moduletwo) {
set $php_root /var/www/Laravel5/public;
}
fastcgi_param PATH_TRANSLATED $php_root/index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_max_temp_file_size 0;
fastcgi_read_timeout 310;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
So, anybody is there? Please look into it and help me to resolve the issue. Thank you so much.

Related

Error: creating session files when running laravel in docker

I have a problem when building laravel with Docker.
Here is my docker-compose.yml file:
services:
php:
build:
context: ./
dockerfile: php.Dockerfile
container_name: php-80
volumes:
- ./:/var/www/html
webserver:
image: nginx:stable-alpine
container_name: nginx-webserver
links:
- php:fpm
environment:
- FPM_HOST=fpm
- FPM_PORT=9000
volumes:
- ./:/var/www/html
- ./docker/nginx_conf:/etc/nginx/conf.d/
ports:
- "8000:80"
db:
image: mysql:5.7
container_name: mysql-db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sampleDB
MYSQL_USER: sampleUser
MYSQL_PASSWORD: password
ports:
- "3306:3306"
My Dockerfile:
FROM php:8.0-fpm-alpine
# install required extension
RUN apk add libxml2-dev
RUN docker-php-ext-install pdo_mysql
# composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
RUN curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/bin --filename=composer
Configuration for nginx:
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost;
root /var/www/html/public;
index index.html index.php;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location / {
try_files $uri $uri /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass fpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
# deny access to . files, for security
location ~ /\. {
log_not_found off;
deny all;
}
}
I run docker-compose up --build. After that, ssh to PHP container and using composer to create laravel project. Configuration permission:
chmod -R 777 storage
chmod -R 775 bootstrap/cache
Pull vendor by
composer install
But when I access url http://localhost:8000/index.php, I get an error: file_put_contents(/var/www/html/storage/framework/sessions/Amv2Kart2HNfbvigAV0WiTE7eVlSb9ghS1kG3V61): Failed to open stream: Invalid argument
[1]: https://i.stack.imgur.com/0dNh4.png
Anyone can help me to solve this problem? Thanks so much.

502 Bad Gateway Docker Symfony Nginx

I have a problem with my docker configuration, my home page on localhost return always 502 Bad Gateway.
Here you can see the architecture of the projet :
https://i.stack.imgur.com/Bfc24.png
the four container running :
https://ibb.co/XpQvnXj
I can access to phpmyadmin :
https://ibb.co/FXLqg8B
But when I go to the nginx port I have this issue :
https://ibb.co/2vs72jF
And this is the contents of the files.
docker-compose.yml :
version: '3'
services:
php:
build:
context: ./php
ports:
- "9000:9000"
volumes:
- ../symfony:/var/www
nginx:
container_name: "nginx"
build:
context: ./nginx
volumes:
- ../symfony:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log
depends_on:
- php
ports:
- "8081:80"
db:
image: mysql:5.6
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
environment:
PMA_HOST: db
depends_on:
- db
php/Dockerfile :
FROM php:8.0.3-fpm
RUN apt-get update \
&& apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;
RUN curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
RUN curl -sSk https://getcomposer.org/installer | php -- && \
mv composer.phar /usr/local/bin/composer
RUN docker-php-ext-configure intl
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
WORKDIR /var/www
CMD composer install ; php-fpm
EXPOSE 9000
nginx/Dockerfile :
FROM nginx:alpine
WORKDIR /var/www
CMD ["nginx"]
EXPOSE 80
nginx/nginx.conf :
user nginx;
worker_processes 4;
daemon off;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 65;
upstream phpserver {
server php:9000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass phpserver;
fastcgi_index index.php;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
deny all;
}
}
}
error.log :
2021/10/13 13:53:04 [error] 25#25: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.16.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://192.168.16.3:9000", host: "localhost:8081"
2021/10/13 13:53:04 [error] 25#25: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.16.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://192.168.16.3:9000", host: "localhost:8081", referrer: "http://localhost:8081/"
I'm new to Docker so the problem is probably obvious

Setting up LEMP in Docker issue with PHP

Have been trying to setup my own LEMP stack locally , nginx and php both seem to be working well alone, however on trying to integrate php in nginx is failing...!!! getting error
403 Forbidden
nginx error logs:
2018/07/22 12:06:48 [error] 9#9: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 172.19.0.4, server: localhost, request: "GET / HTTP/1.1", host: "laradock.localhost:8000"
172.19.0.4 - - [22/Jul/2018:12:06:48 +0000] "GET / HTTP/1.1" 403 571 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36" "172.19.0.1"
Been using below docker image versions:
PHP_TAG=7.1-fpm-alpine
NGINX_TAG=alpine
my docker-compose.yml file
version: "2"
services:
php:
image: php:$PHP_TAG
# restart: always
container_name: "${PROJECT_NAME}_php"
environment:
PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
DB_HOST: $DB_HOST
DB_USER: $DB_USER
DB_PASSWORD: $DB_PASSWORD
DB_NAME: $DB_NAME
DB_DRIVER: $DB_DRIVER
volumes:
- /var/www/ro_www/src/sample_site/:/usr/share/nginx/html
nginx:
image: nginx:$NGINX_TAG
container_name: "${PROJECT_NAME}_nginx"
depends_on:
- php
# - mysqld
environment:
NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
NGINX_ERROR_LOG_LEVEL: debug
NGINX_BACKEND_HOST: php
NGINX_SERVER_ROOT: /var/www/html/
# NGINX_DRUPAL_FILE_PROXY_URL: http://example.com
volumes:
- /var/www/ro_www/src/sample_site/:/usr/share/nginx/html
- ./config/site.conf:/etc/nginx/conf.d/site.conf:ro
# - ./etc/ssl:/etc/ssl
# ports:
# - "8000:80"
# - "3000:443"
labels:
- 'traefik.backend=nginx'
- 'traefik.port=80'
- 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'
mailhog:
image: mailhog/mailhog
container_name: "${PROJECT_NAME}_mailhog"
labels:
- 'traefik.backend=mailhog'
- 'traefik.port=8025'
- 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'
adminer:
container_name: "${PROJECT_NAME}_adminer"
image: wodby/adminer:$ADMINER_TAG
environment:
ADMINER_SALT: adminer-salt
volumes:
- /var/www/ro_www/src/sample_site/adminer/:/usr/share/nginx/html
labels:
- 'traefik.backend=adminer'
- 'traefik.port=9000'
- 'traefik.frontend.rule=Host:adminer.${PROJECT_BASE_URL}'
portainer:
image: portainer/portainer
container_name: "${PROJECT_NAME}_portainer"
command: --no-auth -H unix:///var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- 'traefik.backend=portainer'
- 'traefik.port=9000'
- 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'
traefik:
image: traefik
container_name: "${PROJECT_NAME}_traefik"
command: -c /dev/null --web --docker --logLevel=INFO
ports:
- '8000:80'
- '8080:8080' # Dashboard
volumes:
- /var/run/docker.sock:/var/run/docker.sock
The nginx site.conf file is as follows:
server {
listen 80;
server_name nginx;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root /usr/share/nginx/html;
# }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
#fastcgi_pass php:9000;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Thanks in advance for your help !!! ;)
Since I did not get much feedback, after much trial and error, I got my solution!!
So am posting this, in case somebody may have similar issue.
It seems the issue here was the nginx site.conf file.
server {
listen 80;
listen [::]:80;
index index.php index.html;
server_name laradock.localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
location / {
autoindex on; #to list file in the directory if the index file is missing
}
#### this was where i was facing the issue, the php block
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Another this to note is that nginx can have multiple .conf config files, and it dosent support .htaccess file like apache (the htaccess logic needs to be re-written to a .conf file in the nginx conf.d directory here)
The complete code for my solution can be found at this git repository

Nginx and php-fpm docker compose

I'm trying to create a development environnement for PHP project with Docker-compose.
I just created a docker-compose file that contains 3 docker:
Application: that mounts my code volume
Php: that runs php5-fpm
Nginx: that runs the nginx web server.
I can get an html file through my web server but when I try with a php file I get a 502 Bad Request error.
Error.log:
2016/09/19 16:51:18 [error] 8#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: xxx, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.17.0.3:9000", host: "xxx"
I think that nginx can't connect to php.
Here is my docker-compose file:
# import the code and bind it on /var/www
application:
build: code
volumes:
- ./sites:/var/www/
tty: true
# php container
php:
build: php-fpm
volumes_from:
- application
expose:
- 9000:9000
volumes:
- ./logs/php5-fpm/:/var/log
# nginx container
nginx:
build: nginx
ports:
- 80:80
links:
- php
volumes_from:
- application
volumes:
- ./logs/nginx:/var/log/nginx
php-fpm/Dockerfile:
FROM debian:jessie
RUN apt-get update && apt-get install -y php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-gd php5-imagick php5-curl php5-intl php5-memcache php5-imap
RUN usermod -u 1000 www-data
CMD ["php5-fpm", "-F"]
EXPOSE 9000
nginx/Dockerfile:
FROM debian:jessie
RUN apt-get update && apt-get install -y nginx
ADD nginx.conf /etc/nginx
ADD test.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf
RUN rm /etc/nginx/sites-enabled/default
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
RUN usermod -u 1000 www-data
CMD ["nginx"]
EXPOSE 80
nginx/nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
daemon off;
nginx/test.conf:
server {
listen 80;
server_name xxx;
root /var/www/test;
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /var/log/nginx/test_error.log;
access_log /var/log/nginx/test_access.log;
}
There is no error when launching the docker-compose.
Can someone help me ?
Thanks

Changes to css, js, and static files not reflected on nginx docker container

I created a multi-container application which is about php. When I modify the php file, I can see the changes in the browser. But, when I modify the static files such as css and js, there are no changes in the browser. The following is my Dockerfile code:
Dockerfile
`FROM nginx:1.8
`ADD default.conf /etc/nginx/conf.d/default.conf
`ADD nginx.conf /etc/nginx/nginx.conf
`WORKDIR /Code/project/
`RUN chmod -R 777 /Code/project/
`VOLUME /Code/project
default.conf
`server {
listen 80;
server_name localhost;
root /Code/project/public;
index index.html index.htm index.php;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass fpm:9000;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
nginx.conf
user root;
worker_processes 8;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
client_max_body_size 20m;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}`
docker-compose.yml
webphp:
image: index.alauda.cn/chuanty/local_php
#image: index.alauda.cn/chuanty/local_nginx:snapshot
ports:
- "9000:9000"
volumes:
- .:/Code/project
links:
- cache:cache
- db:db
- es:localhost
extra_hosts:
- "chaunty.taurus:192.168.99.100"
cache:
image: redis
ports:
- "6379:6379"
db:
#image: mysql
image: index.alauda.cn/alauda/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: chuantaiyidev
MYSQL_USER: cty
MYSQL_PASSWORD: chuantaiyidev
MYSQL_DATABASE: taurus
es:
image: index.alauda.cn/chuanty/local_elasticsearch
ports:
- "9200:9200"
- "9300:9300"
server:
#image: index.alauda.cn/ryugou/nginx
image: index.alauda.cn/chuanty/local_nginx:1.1
ports:
- "80:80"
- "443:443"
links:
- webphp:fpm
volumes_from:
- webphp:rw
I guess your problem is "sendfile on" in your nginx.conf.
For development purpose try to set it off in the server-directive of your server block:
server {
...
sendfile off;
}
This will force to reload the static files such as css and js. nginx won't load the file from memory instead.
http://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile
One option is to copy the modified static files directly to the Docker container:
docker cp web/static/main.js container_name:/usr/src/app/static/main.js
web/static is the static directory on your host machine
main.js is the modified file
container_name is the name of the container which can be found with docker ps
/usr/src/app/static is the static directory in your Docker container
If you want to determine exactly where your static files are on your Docker container, you can use docker exec -t -i container_name /bin/bash to explore its directory structure.
I really hope you actually do not copy configuration file into an image!
Docker Best Practice
Docker images are supposed to be immutable, hence at deploy the configuration file (that are depend on a lot [environment] of variables) should be passed to/shared with the container thanks to the docker run option -v|--volume instead.
As for your issue
If you want to see any change when static files are modified you need to docker build and then docker compose up on every modifications in order to actually change the web page. You may not want that (clearly). I suggest you to use shared directories (through the -v option).

Categories