Docker is not running my php project via docker-compose - php

I have my php project. In this project, is a public folder which contains the index.php as a starting point.
The docker-compose.yml file is in the root directory.
So
[Project root directory]
----docker-compose.yml
----public
----------index.php
----other project files and folders
Now I have my docker-compose.yml file, which contains a mysql, phpmyadmin, apache image and a link to the project itself.
It was working before, some weeks ago. I don't remember that I have changed something up, but it does not work anymore.
here is my docker-compose.yml file:
version: '3'
services:
php:
image: docker.team23.de/docker/php:7.2
volumes:
- ./:/app
web:
image: docker.team23.de/docker/apache:2.4-php
environment:
APACHE_DOCUMENT_ROOT: /app/public
volumes:
- ./:/app
ports:
- "3039:80"
db:
image: mysql:5.7
volumes:
- ./mysql-dump:/docker-entrypoint-initdb.d
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: project_name
MYSQL_USER: admin
MYSQL_PASSWORD: admin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
volumes:
db:
docker-compose up -d -V
docker-compose
docker ps
docker ps
the phpmyadmin works fine. I can login to mysql, so this is working too.
But if I open localhost:3039, which should run my project, I get :
The website is unavailable localhost has refused the connection.
logs of web image
Attaching to xxxx_web_1
web_1 | [Sun Jul 21 10:10:57.740369 2019] [so:warn] [pid 1:tid 140066424941416] AH01574: module setenvif_module is already loaded, skipping
web_1 | [Sun Jul 21 10:10:57.740410 2019] [so:warn] [pid 1:tid 140066424941416] AH01574: module headers_module is already loaded, skipping
web_1 | [Sun Jul 21 10:10:57.740417 2019] [so:warn] [pid 1:tid 140066424941416] AH01574: module alias_module is already loaded, skipping
web_1 | AH00526: Syntax error on line 14 of /usr/local/apache2/conf/httpd-extra-basics.conf:
web_1 | DocumentRoot '/app/public' is not a directory, or is not readable

Related

Set up SSL certificate for local laravel project

We have a project at work that consists of two Laravel apps, one for the backend and one for the frontend. A bit ago we forced https and I have been unable to get the apps to work since then. I've tried to ask for help but I have no experience working with webservers or docker so I had a hard time understanding things and did not want to come across as unintelligent by insisting after I got help. I was instructed to install nginx proxy manager and force https from there. I have also installed portainer and set up the two apps with Laravel sail. I believe at this point I need to somehow set up a host for the front end and force https from NPM on it. Currently, when I try to access the front end I get the3 following error:
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Accepted
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Invalid request (Unsupported SSL request)
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Closing
Here are the two docker-composes I have for sail
The back end
# For more information: https://laravel.com/docs/sail
version: "3"
services:
mci.back:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
image: sail-8.0/app
ports:
- "8001:80"
environment:
LARAVEL_SAIL: 1
volumes:
- ".:/var/www/html"
- "./docker/configs:/etc/supervisor/conf.d"
networks:
- sail
container_name: papa-dashboard
pgsql:
image: postgres:13
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'sailpgsql:/var/lib/postgresql/data'
networks:
- mci_events_sail
- sail
healthcheck:
test:
[
"CMD",
"pg_isready",
"-q",
"-d",
"${DB_DATABASE}",
"-U",
"${DB_USERNAME}"
]
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
mci_events_sail:
external: true
volumes:
sailpgsql:
driver: local
The front end
# For more information: https://laravel.com/docs/sail
version: "3"
services:
mci-front:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
image: sail-8.0/app
ports:
- "8002:80"
environment:
LARAVEL_SAIL: 1
volumes:
- ".:/var/www/html"
networks:
- sail
- mci_events_sail
container_name: papa-frontend
networks:
sail:
driver: bridge
mci_events_sail:
external: true

PHP-FPM docker container got different behavior depending engine (docker-compose and swarm)

One PHP-FPM container (7.2), member of classical LAPP stack, correctly exposes port 9000 when launched with docker-compose but nothing when started by Docker Swarm. Should I mention that container is running (see output below) and I can launch a TTY bash on it.
So with docker-compose, web application is fully functionnal, but with Swarm, Apache issues a 503 Service Unavailable. Nothing is changed between tests with different engines. Do you have any clue about this behaviour ?
docker-compose.yml
version: '3.5'
services:
postgres:
env_file: ./.env
image: "postgres:9.5.24"
volumes:
- database:/var/lib/postgresql/data
networks:
- internal
adminer:
image: adminer
networks:
- internal
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.adminer.rule=Host(`adminer.example.com`)"
- "traefik.http.routers.adminer.entrypoints=websecure"
- "traefik.http.routers.adminer.tls.certresolver=letsencryptresolver"
- "traefik.http.services.adminer.loadbalancer.server.port=8080"
- "traefik.port=80"
apache:
env_file: ./.env
image: visio_rdv_apache:latest
build:
context: docker/images/apache2.4
dockerfile: Dockerfile
args:
UID: ${HOST_UID}
ROOT_URL: ${ROOT_URL}
ports:
- 8000:80
environment:
FPM_HOST: php:9000
ROOT_URL: ${ROOT_URL}
volumes:
- ${LOGS_DIR}/apache/:/var/log/httpd/
- ${RELATIVE_APP_PATH}:/var/www/html
links:
- postgres
- php
networks:
- internal
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.visio_rdv.rule=Host(`test.example.com`)"
- "traefik.http.routers.visio_rdv.entrypoints=websecure"
- "traefik.http.routers.visio_rdv.tls.certresolver=letsencryptresolver"
- "traefik.http.services.visio_rdv.loadbalancer.server.port=80"
- "traefik.port=80"
php:
env_file: .env
links:
- ftp
image: visio_rdv_php:latest
build:
context: docker/images/php
dockerfile: Dockerfile
args:
UID: ${HOST_UID}
TIMEZONE: ${TIMEZONE}
PROXY: ${http_proxy}
volumes:
- ftp_data:/var/www/ftp:rw
- ${RELATIVE_APP_PATH}:/var/www/html
networks:
- internal
ftp:
env_file: .env
image: "fauria/vsftpd:latest"
ports:
- "9520:20"
- "9521:21"
- "21100-21110:21100-21110"
environment:
FTP_USER: ${FTP_USER}
FTP_PASS: ${FTP_PASS}
PASV_MIN_PORT: 21100
PASV_MAX_PORT: 21100
volumes:
- ftp_data:/home/vsftpd/${AUTOMATION_CLIENT_NAME}:rw
networks:
- internal
volumes:
ftp_data:
database:
networks:
traefik-public:
external: true
internal:
external: false
With Docker Swarm
Apache logs :
[Wed Aug 04 07:35:16.382246 2021] [proxy:error] [pid 11] (111)Connection refused: AH00957: FCGI: attempt to connect to 10.0.4.93:9000 (*) failed
[Wed Aug 04 07:35:16.382314 2021] [proxy_fcgi:error] [pid 11] [client 10.0.0.2:1035] AH01079: failed to make connection to backend: php, referer: http://test.example.com/
Swarm services list :
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
um2txtpz8534 traefik_reverse-proxy replicated 1/1 traefik:v2.4
ahf7uukapxbr my_stack_adminer replicated 1/1 adminer:latest
ue8qekmg0ff0 my_stack_apache replicated 1/1 my_stack_apache:latest my_stack*:8000->80/tcp
x9igaslhsx11 my_stack_ftp replicated 1/1 fauria/vsftpd:latest *:9520-9521->20-21/tcp, *:21100-21110->21100-21110/tcp
jpk4qzqs1tfx my_stack_php replicated 1/1 my_stack_php:latest
ih67rh82vp9e my_stack_postgres replicated 1/1 postgres:9.5.24
I tried to add net-tools to the PHP image, in order to manually test the connection with nc. Same result, php container instance IP is correctly resolved, but any TCP connection to port 9000 is refused.
I use a lot environment vars, and in order to palliate missing feature with Swarm, I use the docker-compose config command output to generate complete docker-compose.yml file.
With docker-compose
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
my_stack_adminer_1 entrypoint.sh docker-php-e ... Up 8080/tcp
my_stack_apache_1 /bin/sh -c apachectl -D FO ... Up 0.0.0.0:8000->80/tcp
my_stack_ftp_1 /usr/sbin/run-vsftpd.sh Up 0.0.0.0:9520->20/tcp, 0.0.0.0:9521->21/tcp, 0.0.0.0:21100->21100/tcp, 0.0.0.0:21101->21101/tcp, 0.0.0.0:21102->21102/tcp,
0.0.0.0:21103->21103/tcp, 0.0.0.0:21104->21104/tcp, 0.0.0.0:21105->21105/tcp, 0.0.0.0:21106->21106/tcp, 0.0.0.0:21107->21107/tcp,
0.0.0.0:21108->21108/tcp, 0.0.0.0:21109->21109/tcp, 0.0.0.0:21110->21110/tcp
my_stack_php_1 php-fpm -R -F Up 9000/tcp
my_stack_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
Here are a few things I'd try:
Use docker service inspect to see if the configuration matches what you expect it to be.
Jump into the php container and see what port it's actually listening on.
Did you intend to expose the apache server directly? I would imagine you'd use traefik in front of that since you already have in the mix.

Database connection refused for Laravel artisan command with Docker

I am trying to run Laravel using Docker locally. Everything works fine expect the database. This is how my docker-compose looks like:
services:
app:
build:
context: ./
dockerfile: ./docker/Dockerfile
container_name: my-app
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- my-network
db:
image: mysql:8.0
container_name: my-db
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
ports:
- 3307:3306
volumes:
- ./docker/mysql:/docker-entrypoint-initdb.d
networks:
- my-network
nginx:
image: nginx:alpine
container_name: my-nginx
ports:
- 8001:80
volumes:
- ./:/var/www
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d
networks:
- my-network
My .env file looks like this:
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=admin
DB_PASSWORD=
When I run php artisan migrate:fresh within the app container, I am getting the following message:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
Can someone see what is the problem here?
UPDATE: When I run docker-compose ps I can see
NAME COMMAND SERVICE STATUS PORTS
my-app "docker-php-entrypoi…" app running 9000/tcp
my-db "docker-entrypoint.s…" db restarting
my-nginx "/docker-entrypoint.…" nginx running 0.0.0.0:8001->80/tcp, :::8001->80/tcp
This is the log when I run docker-compose logs db
my-db | 2021-07-29T20:18:37.340769Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 104
my-db | 2021-07-29T20:18:37.354423Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
my-db | 2021-07-29T20:18:37.354605Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
my-db | 2021-07-29T20:18:37.356184Z 0 [ERROR] [MY-010119] [Server] Aborting
my-db | 2021-07-29T20:18:37.358746Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.

Docker: Forbidden You don't have permission to access this resource

Im trying to reach http://localhost:8100 and all i get is: "Forbidden
You don't have permission to access this resource.
Apache/2.4.38 (Debian) Server at localhost Port 8100"
In the src/ i have the docker file and a php folder in which i have both index.php and mysql.php files.
The docker-compose.yml looks like this:
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test_db
MYSQL_USER: devuser
MYSQL_PASSWORD: devpass
ports:
- "9906:3306"
web:
image: php:7.4.0-apache
container_name: php_web
depends_on:
- db
volumes:
- ./php/:/var/www/html/
links:
- db
ports:
- "8100:80"
stdin_open: true
tty: true
Commands on the terminal:
docker-compose up -d
docker exec -ti php_web sh
docker-php-ext-install mysqli
When I try to reach localhost:8100/mysql.php it works fine but when i try to open either localhost:8100 or localhost:8100/index.php I get the error.
Any clues on what could be causing it? I hope Im being clear with my question.
Thanks in advance!
As per output of docker exec -ti php_web ls -la /var/www/html/, i can see space in the name of the file :
-rw-r--r-- 1 root root 70 Jul 11 23:06 ' index.php'
drwxr-xr-x 5 root root 160 Jul 11 22:40 .
drwxr-xr-x 1 root root 4096 Nov 22 2019 ..
drwxr-xr-x 4 root root 128 Jul 11 22:31 includes
-rwxr-xr-x 1 root root 118 Jul 11 22:43 mysql.php
rename it and remove the space
mv ' index.php' index.php

Mysql Exited on Docker Container

I want to make a web development platform on MacOS by using Docker. I installed nginx, and php7-fpm container and they're running and communicating each other. But after installing mysql container, mysql container was exited. I don't know why it exited.
This is docker ps -a output:
2955d2d5c392 nginx "/sbin/my_init" 38 seconds ago Up 36 seconds 0.0.0.0:8080->80/tcp dockertutorial_web_1
ec3c16795f05 php:7-fpm "docker-php-entrypoin" 38 seconds ago Up 37 seconds 9000/tcp dockertutorial_php_1
835e91ba927a mysql:latest "docker-entrypoint.sh" 38 seconds ago Exited (0) 37 seconds ago dockertutorial_mysql_1
As you can see, mysql was exited.
This is my docker-compose.yml file:
web:
image: nginx
ports:
- "8080:80"
volumes:
- ./src/public:/var/www/public
- ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./src/public:/var/www/public
links:
- mysql
mysql:
image: mysql:latest
ports:
- "3306:3306"
volumes:
- /var/lib/mysql
command: "true"
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
Any suggesstion to solve it?
You are overriding command for MySQL image with true which will be run instead of mysqld.
Remove command: "true" from docker-compose.yml from mysql service and it will start mysqld.
See this Dockerfile for reference.
https://github.com/docker-library/mysql/blob/c207cc19a272a6bfe1916c964ed8df47f18479e7/5.7/Dockerfile#L63

Categories