Docker Compose: Nginx and PHP-FPM not working - php

I'm testing docker compose with Nginx and php-fpm, but this fail.
My docker-compose.yml:
version: '2'
services:
nginx:
container_name: nginx
build:
context: ./dockerfiles/nginx/
dockerfile: Dockerfile
volumes:
- ./project/:/usr/share/nginx/html/
ports:
- "8000:80"
links:
- php
php:
container_name: php-fpm
image: php:7-fpm
volumes:
- ./project/:/var/www/html/
ports:
- "9000:9000"
This is my dockerfile Nginx:
FROM nginx:latest
COPY config/default.conf /etc/nginx/conf.d/
And dafault.conf file:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
when I try localhost: 8000 returns the following message:
"File not found."
but, the index.php is in the project/ path.
that I am wrong?

I think you need to use volumes_from in your nginx container in the compose file, now you have in nginx:
volumes:
- ./project/:/usr/share/nginx/html/
And in php
volumes:
- ./project/:/var/www/html/
They should be the same.

Related

docker nginx 404 not found

Why I get this error when visit localhost:8080!
Any suggestion to solve this issue is welcome because I spend many time for it and I changed PHP docker file and nginx file many times, similar version with laravel framework is ok for me.
*1 open() "/var/www/html/myapp404" failed (2: No such file or directory)
Note that myapp folder contains index.php and other files but it is not a Laravel framework.
My docker compose:
version: '3.8'
services:
nginx:
build:
context: .
dockerfile: nginx.dockerfile
ports:
- 8080:80
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ${PWD}/myapp:/var/www/html/myapp
working_dir: /var/www/html/myapp
ports:
- "9000:9000"
mysql:
image: yobasystems/alpine-mariadb
ports:
- "3308:3308"
volumes:
- ./mariadb/data:/var/lib/mysql
- ./mariadb/my.conf:/etc/my.cnf
environment:
MYSQL_ROOT_PASSWORD: "111"
MYSQL_DATABASE: myapp
MYSQL_USER: root
MYSQL_PASSWORD: "111"
restart: always
My default.conf => Nginx:
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/myapp;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on php:9000
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;
}
}
nginx:
FROM nginx:stable-alpine
ADD nginx/default.conf /etc/nginx/conf.d/default.conf
php :
FROM dwchiang/nginx-php-fpm:latest
Thanks.

Docker - Communication between two PHP containers: "Connection Refused"

So, I have a problem with my docker setup for a project I'm working on. Using Docker and docker-compose I have set up a few containers as seen below. I can reach both php services via the browser no problem. dev.drmobile.local refers to the Magento service and dev.dronline.local refers to the Symfony service. The problem is that when the Magento service needs data from the Symfony service, I get an error stating Unable to Connect to tcp://dev.dronline.local:80. Error #111: Connection refused. I have tried merging both services in 1 container, but the problem is also present in that situation.
All other communication between containers seems to work fine.
I'm not sure on the port setup I've used, but it doesn't seem to trigger any errors.
Both php containers use the same image created from a Dockerfile, with a slightly different init script.
Any help and tips will be greatly appreciated.
docker-compose.yml
version: '3.3'
networks:
drmobile:
services:
nginx-service:
image: nginx:stable-alpine
container_name: drmobile-nginx-container
ports:
- "8080:80"
volumes:
- ./:/var/www/html
- ./.docker/nginx/:/etc/nginx/conf.d/
depends_on:
- symfony-service
- magento-service
networks:
- drmobile
magento-service:
container_name: drmobile-magento-container
build:
context: .
dockerfile: ./.docker/php/Dockerfile
ports:
- "9000:9000"
volumes:
- ./:/var/www/html
- ./.docker/php/php.ini:/usr/local/etc/php/php.ini
- ./.docker/php/magento/docker-install.sh:/var/www/html/docker-install.sh
networks:
- drmobile
symfony-service:
container_name: drmobile-symfony-container
build:
context: .
dockerfile: ./.docker/php/Dockerfile
ports:
- "9001:9000"
volumes:
- ./:/var/www/html
- ./.docker/php/php.ini:/usr/local/etc/php/php.ini
- ./.docker/php/symfony/docker-install.sh:/var/www/html/docker-install.sh
networks:
- drmobile
mysql-service:
image: mysql:5.7
container_name: drmobile-mysql-container
ports:
- "3306:3306"
volumes:
- ./.docker/data/mysql-data:/var/lib/mysql
- ./.docker/mysql/:/docker-entrypoint-initdb.d/
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: dynalinq
MYSQL_PASSWORD: password
networks:
- drmobile
redis-service:
image: redis:2.8
container_name: drmobile-redis-container
ports:
- "6379:6379"
networks:
- drmobile
varnish-service:
build:
context: .docker/varnish
container_name: drmobile-varnish-container
ports:
- "80:80"
networks:
- drmobile
depends_on:
- nginx-service
elasticsearch:
image: elasticsearch:1.7.6
container_name: drmobile-elasticsearch-container
networks:
- drmobile
volumes:
- ./.docker/data/elasticsearch-data:/usr/share/elasticsearch/data
environment:
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
HOSTNAME: "elasticsearch-dev"
.docker/nginx/dev.dronline.local.conf
server {
listen 80;
root /var/www/html/symfony/web;
server_name dev.dronline.local;
access_log /var/log/nginx/dronline_access.log custom_dronline;
error_log /var/log/nginx/dronline_error.log;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass drmobile-symfony-container:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
}
}
.docker/nginx/dev.drmobile.local.conf
server {
listen 80 default_server;
server_name dev.drmobile.local;
root /var/www/html/magento;
index index.html index.php;
access_log /var/log/nginx/dev.drmobile.local_access.log custom;
error_log /var/log/nginx/dev.drmobile.local_error.log;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php$ { ## Execute PHP scripts
fastcgi_pass drmobile-magento-container:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE base;
fastcgi_param MAGE_RUN_TYPE website;
include fastcgi_params;
}
}

Docker with PHP Nginx unable to load image or js - 404 not found

I am deploying 2 docker containers (nginx and php fpm) in my windows 10 pro local machine.
I can get php script executed correctly.
For example: http://localhost:8888/phpinfo.php --> this return correctly.
But other than php script (e.g. image, js or css) it giving me not found.
For example: http://localhost:8888/image.jpg --> not found
Whats possibly went wrong here?
here is my docker compose file:
version: '3.7'
services:
# The Web Server
web:
container_name: emm_web
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ../log/:/var/log
ports:
- 8888:80
# The PHP Application
app:
container_name: emm_app
build:
context: ./
dockerfile: app.dockerfile
volumes:
- ../www/:/var/www
depends_on:
- web
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
And here is my nginx vhost.conf:
server {
listen 80;
index index.php index.html;
root /var/www;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Thank you :)
You need to share files for nginx container. Try this:
# The Web Server
web:
container_name: emm_web
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ../log/:/var/log
# !! nginx need this volume !!
- ../www/:/var/www:ro
ports:
- 8888:80
That readonly volume will make the files in the container available.

run symfony2 app with docker [File not found.]

I'm trying to run my symfony app with docker. I have downloaded this bundle eko/docker-symfony
I have copy my symfony project inside of my docker directory.
If I refresh with localhost, I have this error: File not found.
If I put port 81 after localhost the page of Kibana will shop up.
When I run docker ps, I have noticed that the IP of all my containers is 0.0.0.0
docker-compose.yml
version: '2'
services:
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
php:
build: ./php-fpm
expose:
- "9000"
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
links:
- db
nginx:
build: ./nginx
ports:
- "80:80"
links:
- php
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- php
- nginx
symfony.conf
server {
server_name symfony.dev;
root /var/www/symfony/web;
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
I think the problem is port 80. This probably looks on your host for a file.
You can either try to run nginx under a different port f.e. 8001
nginx:
build: ./nginx
ports:
- "8001:80"
and call
http://localhost:8001
or use a hosts name. To quote the readme of eko/docker-symfony
...and do not forget to add symfony.dev in your /etc/hosts file.
like
127.0.0.1 symfony.dev
Then you can call
http://symfony.dev

Can't see staring installation page of wordpress docker container based on alpine linux

Here is my configuration :
OS : Windows 10 Enterprise x64 [Version 10.0.14393]
Docker Toolbox: Docker version 1.12.5, build 7392c3b
docker-compose version 1.9.0, build 2585387
My docker-compose.yml:
version: '2'
services:
wordpress:
image: wordpress:4.7.0-php7.0-fpm-alpine
links:
- "mysql:mysql-database"
ports:
- 8080:80
- 9000:9000
expose:
- "3306"
- "8080"
- "80"
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql
ports:
- 3306:3306
expose:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: example
Starting up this with : docker-compose up -d
After this don't see wordpress installation page on http://192.168.99.100:8080/
If I change wordpress tag to 4.7.0-php7.0-apache then everything works fine .Is there bug in alpine wordpress image or I just need to open some ports?
this alpine image was made with just php-fpm and need to be used alongside with an webserver like nginx.
There is my approach:
In the docker-compose.yml
version: '2'
services:
web:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./site.conf:/etc/nginx/conf.d/default.conf:ro
- /etc/localtime:/etc/localtime:ro
volumes_from:
- wordpress
wordpress:
image: wordpress:4.7.0-php7.0-fpm-alpine
environment:
WORDPRESS_DB_PASSWORD: example
WORDPRESS_DB_HOST: mysql
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: wordpress
And the site.conf:
server {
listen 80;
index index.php index.html;
server_name $hostname;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

Categories