Cannot start service web: OCI runtime create failed: - php

can I ask some help please when I execute the command docker-compose up -d
I get error can you help me how can I execute php using nginx
Removing nginx-container
mysql-container is up-to-date
php-container is up-to-date
Recreating 2e6f7b9915c6_nginx-container ... error
ERROR: for 2e6f7b9915c6_nginx-container Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/c/webdock/firstweb/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged\\\" at \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged/etc/nginx/conf.d\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/c/webdock/firstweb/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged\\\" at \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged/etc/nginx/conf.d\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.
Here is my docker-compose
version: "3.7"
services:
web:
image: nginx:latest
container_name: nginx-container
ports:
- "8080:80"
volumes:
- ./:/var/www/firstweb
- ./default.conf:/etc/nginx/conf.d/
links:
- php
php:
image: php:7-fpm
container_name: php-container
db:
image: mysql
container_name: mysql-container
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql-data:/var/lib/mysql
expose:
- 3306
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: rootpass
and my default.conf
server {
listen 80;
index index.php;
server_name app.dev;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/firstweb;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

change this - ./default.conf:/etc/nginx/conf.d/ to :
- ./default.conf:/etc/nginx/conf.d/default.conf
you can see in the error that Docker trying to mount a file default.conf to a folder conf.d

Related

Docker-Compose NGINX and PHP - Can server html files but php gives bad gateway

I am trying to run nginx and php in docker-compose. I am able to build the containers and when I browse to an html file in my browser nginx serves it. But when I try to browse a php file I just get 502 Bad Gateway.
I'm aware that it may be something to do with the server name in my nginx configuration file, since the tutorial I got it from mentions this needs to be correct. But I've tried changing it to 'localhost' and 'ip-of-my-dockerhost' with same result.
I'm also aware I should look at the log files. However I am a bit of a linux novice. When I open Portainer, go to the container called Web and execute a shell, if I go:
cd /var/log/nginx ; ls
I see two files called access.log and error.log
however if I type
cat error.log
nothing happens! I get a new blank line with a blinking cursor that never outputs anything. The shell is then 'frozen' until I press CTRL-C to kill the task.
Contents of docker-compose.yml
version: "3.7"
#############################
#
# NETWORKS
#
#############################
networks:
main:
external:
name: main
default:
driver: bridge
###########################
#
# SERVICES
#
###########################
services:
# All services / apps go below this line
portainer:
container_name: Portainer
image: portainer/portainer:latest
restart: unless-stopped
command: -H unix:///var/run/docker.sock
networks:
- main
ports:
- "$PORTAINER_PORT:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- $DATADIR/portainer:/data # Change to local directory if you want to save/transfer config locally
environment:
- TZ=$TZ
<<snip as don't believe relevant - a bunch of other containers here such as influxdb, radarr etc>>
web:
container_name: Web
image: nginx:latest
networks:
- main
ports:
- 81:80
environment:
- PUID=$PUID
- PGID=$PGID
volumes:
- $CONFIGDIR/nginx/site.conf:/etc/nginx/conf.d/default.conf
- $DATADIR/nginx/code:/code
php:
container_name: php
image: php:7-fpm
networks:
- main
ports:
- 9090:9000
environment:
- PUID=$PUID
- PGID=$PGID
volumes:
- $CONFIGDIR/nginx/site.conf:/etc/nginx/conf.d/default.conf
- $DATADIR/nginx/code:/code
contents of $CONFIGDIR/nginx/site.conf
server {
index index.php index.html;
server_name 192.168.1.7; ## This is the IP address of my docker host but I've also tried 'localhost' and 'php-docker.local'
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9090;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
9090 is an exposed port. That means you can reach localhost:9090 for the PHP container but not for internal container communication.
Change your site.conf:
fastcgi_pass php:9090; => fastcgi_pass php:9000;

After docker compose localhost:8000 not open page in browser

Hello i'm newbie in docker. I have project on laravel 9 with node version 12.14.0,PostgreSql 10,PHP 8.1.2
This my git repository:https://github.com/Daniil1996-vrn/DEVJuniorPHP/tree/main/DEVJuniorPHP
I create docker file, webserver ngnix conf file (but when i'm creating project i usr artisan server) on this repository:https://github.com/othyn/docker-compose-laravel#running-attached
This is my docker-compose.yml:
version: "3.7"
networks:
laravel:
volumes:
database:
services:
database:
image: postgres:10
container_name: postgres
restart: "no"
volumes:
- .:/var/lib/postgresql/data
networks:
- laravel
ports:
- 5432:5432
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "admin1234"
POSTGRES_DB: "DEVJuniorPHP"
composer:
image: composer:latest
container_name: composer
volumes:
- ./:/app
working_dir: /app
command: composer install
node:
image: node:12
container_name: node
volumes:
- ./:/app
working_dir: /app
command: npm install
app:
container_name: app
restart: "no"
volumes:
- ./:/var/www
networks:
- laravel
depends_on:
- composer
- node
build:
context: .
dockerfile: ./docker/app/dockerfile
command: php-fpm
webserver:
image: nginx:stable
container_name: webserver
restart: "no"
volumes:
- ./:/var/www
- ./docker/webserver/nginx.conf/
networks:
- laravel
ports:
- 8000:8000
depends_on:
- database
- app
Docker File:
FROM php:8.1.4-fpm-alpine3.14
# Update package manager ready for deps to be installed
RUN apk update
# Set the working directory of the container to the hosted directory
WORKDIR /var/www
nginx.conf:
server {
listen 8000;
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/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location ~ \.php$ {
try_files $uri =404;
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;
# Uncomment to extend nginx's max timeout to 1 hour
# fastcgi_read_timeout 3600;
}
}
When i run command in terminal Visual Studio code docker-compose up -d i next have messagess in terminal:
Starting node ... done
Starting composer ... done
Starting postgres ...
Starting postgres ... done
Recreating webserver ... done
PS D:\DEVJuniorPHP\DEVJuniorPHP> docker-compose up -d
Starting node ... done
Starting postgres ...
Starting postgres ... done
app is up-to-date
webserver is up-to-date
But whene i go to page localhost:8000 in browser i see the message:Can't access site
Please help me resolve this problem
Error is that the nginx vhost is pointing to the wrong folder.
You didn't map the nginx.conf volume into the container volume so it doesn't really find the path to the application.
In the volume part of the webserver service, you must put the path of the vhost container:
- ./docker/webserver/nginx.conf:/etc/nginx/nginx.conf
Get back to me if it's good !

Afterlogic Webmail - Nginx to Apache "Cannot declare class, name is already in use"

I downloaded the Afterlogic Webmail from the official site, it works fine on apache.
Moving it to the official docker which uses apache it works fine (https://github.com/afterlogic/docker-webmail-pro)
Moving it to my docker setup I use for every other project that uses nginx seems to cause the php classes to load twice.
Fatal error: Cannot declare class Aurora\Modules\ActivityHistory\Module, because the name is already in use in /var/www/modules/ActivityHistory\/Module.php on line 245
This is the default project pulled straight from https://afterlogic.com/download/webmail-pro-php.zip.
nginx configuration
server {
listen 80;
index index.php index.html;
root /var/www;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass ${LARANAME}:9000;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
docker-compose.yml
version: '3.7'
services:
app:
container_name: wbmail_app_dev
build:
context: .
dockerfile: docker/app.dev.dockerfile
ports:
- '4721:80'
volumes:
- './:/var/www/'
networks:
- wbmail-network-dev
ports: []
web:
container_name: wbmail_web_dev
build:
context: .
dockerfile: docker/web.dev.dockerfile
ports:
- '4721:80'
volumes:
- './:/var/www/'
environment:
- LARANAME=wbmail_app_dev
networks:
- wbmail-network-dev
db:
container_name: wbmail_db_dev
image: 'mariadb:latest'
environment:
MYSQL_DATABASE: wbmail_test
MYSQL_ROOT_PASSWORD: cr0ssf1r3
networks:
- wbmail-network-dev
networks:
wbmail-network-dev:
driver: bridge
phpinfo(): https://codepasta.app/paste/c1e7nmvout2tbkhn2dk0
It turned out that there was a bug in the code, which caused attempts to include the same file multiple times. The issue has been corrected and the fix will be included in the product starting from the next version.
For those who experience the issue and need to correct it on their installation, locate the following line in system/autoload.php file:
$sModuleName = substr($sModuleClassName, 0, -7);
and replace it with:
$sModuleName = substr($sModuleClassName, 0, strpos($sModuleClassName, '\\'));
Thank you Andrew Gosselin for researching this and offering a fix.

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.

Permission Denied Nginx Docker

I'm using docker compose to boot up a development workspace, consisting of php, nginx and mysql. Everything boots, static html get's served, but when trying to start a laravel app, i get the following error:
The stream or file "/home/html/storage/logs/laravel-2019-06-10.log" could not be opened: failed to open stream: Permission denied
I searched around and it looked like a permissions issue? Do note, that the docker with just the database and the build in php server does seem to work.
My docker-compose.yml
version: "3"
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: "root"
ports:
- 3306:3306
php-fpm:
image: php:7.3-fpm-alpine
links:
- db
volumes:
- "./:/home/html/"
nginx:
image: nginx:1-alpine
ports:
- "8080:80"
links:
- php-fpm
volumes:
- "./site.conf:/etc/nginx/conf.d/default.conf"
- "./:/home/html/"
My nginx config:
server {
index index.php index.html;
listen 80 default_server;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /home/html/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Kind regards :)
Enter the php-fpm container:
docker-compose -i -t exec php-fpm /bin/sh
Then change access rights of storage folder:
chmod -r 777 /home/html/storage
Cause it's local development environment, correct rights doesn't matter.

Categories