Set up SSL certificate for local laravel project - php

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

Related

docker is not reading from docker-compose.yml

It seems that when i run Docker compose up, docker is not reading from docker-compose.yml.
It seems like it is loading images from cache or i don't think where is finding them.
Bellow is my docker-compose.yml
version: '3'
services:
httpd:
image: httpd:latest
user: root
ports:
- "80:80" # Default Apache port (Default on PHP 7.4)
- "8073:8073" # PHP 7.3 Apache port
- "8074:8074" # PHP 7.4 Apache port
- "8081:8081" # PHP 8.1 Apache port
volumes:
- ./:/var/www/html/myApp/:rw
- ./dev/Docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
restart: on-failure
container_name: httpd
networks:
- mb-frontend
php8.1-fpm:
build: ./dev/Docker/php-fpm/8.1
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php8.1-fpm
networks:
- mb-frontend
- mb-backend
php7.4-fpm:
build: ./dev/Docker/php-fpm/7.4
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.4-fpm
networks:
- mb-frontend
- mb-backend
php7.3-fpm:
build: ./dev/Docker/php-fpm/7.3
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.3-fpm
networks:
- mb-frontend
- mb-backend
db:
image: mariadb:10.3.5
environment:
MYSQL_ROOT_PASSWORD: myPassword
MYSQL_USER: dev
MYSQL_PASSWORD: myPassword
ports:
- "3306:3306"
volumes:
- /root/Bureau/mysql:/var/lib/mysql/:rw
- ./dev/Docker/mariadb/conf.d/:/etc/mysql/conf.d/:rw
- ./dev/Docker/mariadb/config/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: on-failure
container_name: db
networks:
- mb-backend
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
volumes:
- /root/Bureau/phpmyadmin:/var/lib/mysql/
networks:
- mb-backend
depends_on:
- db
redis:
image: redis:6.2
container_name: redis
ports:
- "6379:6379"
networks:
- mb-backend
networks:
mb-frontend:
driver: bridge
mb-backend:
driver: bridge
I commented some images on docker-compose.yml but when i tape the command Docker compose up on terminal, all images even commented images are Up.
Can anyone help me how i force docker to read images from the edited docker-compose.yml
Good practice would be do use:
docker compose down
and then
docker compose up
UPDATE:
Next I would suggest to clean up your containers:
List all containers:
docker ps -a
Remove those you don't want because they might still be in the system
docker rm <CONTAINER ID/NAME>
How to Stop & Remove a running container by ID or Name?
The command is actually docker compose up.
The command docker-compose has been deprecated as of latest version. We can now use docker compose without the hyphen(-).
You can use docker-compose -f <path-to-compose-file> to pass in the compose file.
Example:
docker compose -f docker-compose.yml up
Reference documentation: https://docs.docker.com/compose/reference/

MacOs - localhost file not found 404

Can someone please help.
I was running successfully my Symfony project via Docker containers. Suddenly when I access http://localhost/ I get the File not found. error?
I now that it means that system can not locate my files, but I am not sure what happened.
I see that my containers are built and running okay.
Also the same message I get when I try to test app endpoints through Postman.
I am on Mac Monterey 12.4.
Everything was working fine couple of hours ago. I just switched branches to change something, then switched back. The problem was on both branches..
Can someone help, I do not know what to do?
Docker config:
services:
db:
image: postgres:${POSTGRES_VERSION:-12}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-name}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pass}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
volumes:
- $PWD/postgres-data:/var/lib/postgresql/data:rw
profiles:
- db-in-docker
ports:
- "5432:5432"
networks:
- symfony
redis:
image: "redis:alpine"
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
volumes:
- $PWD/redis-data:/var/lib/redis
- $PWD/redis/redis.conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
networks:
- symfony
php:
container_name: "backend_php"
build:
context: ..
dockerfile: docker/php/Dockerfile
target: dev
args:
TIMEZONE: ${TIMEZONE}
volumes:
- symfony_docker_app_sync:/var/www/symfony/
depends_on:
- redis
networks:
- symfony
nginx:
build:
context: ./nginx
volumes:
- ../:/var/www/symfony/
ports:
- 80:80
depends_on:
- php
networks:
- symfony
env_file:
- .env.nginx.local
First of all: Why do you donĀ“t use the built in symfony server for local development? However - how looks your docker container configuration for your webserver?

Docker compose: getaddrinfo for mariadb failed

I'm quite bad at creating docker-compose and I currently have a problem when I try to build a new project.
After the build I can't access my mariadb server within my php app container, I've got this error:
PDO::__construct(): php_network_getaddresses: getaddrinfo for mariadb
failed: Name does not resolve
So I know something is misconfigured but I don't know what, yet. I tried many changes but nothing that worked.
Here is my current docker-compose.yml:
version: "3.8"
networks:
# used by some services (php) to communicate with other docker-compose.yaml
censored.com:
external:
name: censored.com
services:
app:
build:
context: .
target: symfony_php
args:
- secret=id=composerauth,src=${HOME}/.composer/auth.json
restart: unless-stopped
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
environment:
APP_ENV: dev
HOST: www.censored.lan
networks:
- default
- censored.com
volumes:
- ./:/srv/app:rw,cached
- ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini
- ${HOME}/.composer/auth.json:/root/.composer/auth.json
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
- ./var/cache:/srv/app/cache:rw
- ./var/log:/srv/app/logs:rw
depends_on:
- mariadb
extra_hosts:
- www.censored.lan:127.0.0.1
nginx:
build:
context: .
target: symfony_nginx
args:
- secret=id=composerauth,src=${HOME}/.composer/auth.json
restart: unless-stopped
depends_on:
- app
environment:
NGINX_DOMAIN: www.censored.lan
ports:
- 8001:80
volumes:
- ./docker/nginx/templates/dev.conf.template:/etc/nginx/templates/default.conf.template:ro
- ./docker/nginx/rules/rules.dev.conf:/etc/nginx/rules.conf:ro
- ./public:/srv/app/public:ro
- ./src:/srv/app/src:ro
mariadb:
image: mariadb:10.7
environment:
MYSQL_ROOT_PASSWORD: changeme
MYSQL_DATABASE: database
MYSQL_USER: user
MYSQL_PASSWORD: changeme
networks:
- default
- censored.com
ports:
- '3307:3306'
restart: on-failure
volumes:
- db_data:/var/lib/mysql
volumes:
db_data: {}
Can someone help me to fix the issue please?
Thanks !
The problem wasn't related to my docker-compose configuration file.
My app is a PHP Symfony app and it was doing a "cache:clear" after the initial "composer install" during the build. The "cache:clear" was triggering calls to the database which wasn't ready yet.
To solve this I just had to set my mariadb version to my "DATABASE_URL" parameter in my Symfony app, to avoid useless database queries.

Docker PHP7.x Codeception Selenium WebDriver throws net::ERR_CONNECTION_REFUSED

I am trying to set up Codeception to do Acceptance and Functional testing for my web app. Below are my files:
docker-compose.yml
version: '3.7'
services:
# nginx - web server
nginx:
build:
context: ./docker-config/nginx
dockerfile: ./Dockerfile
env_file: &env
- ./cms/.env
init: true
ports:
- "8000:80"
volumes:
- cpresources:/var/www/project/cms/web/cpresources
- ./cms/web:/var/www/project/cms/web:cached
networks:
mmc-network:
aliases:
- mmc.nginx
# php - run php-fpm
php:
build: &php-build
context: ./docker-config/php-prod-craft
dockerfile: ./Dockerfile
depends_on:
- "mysql"
- "redis"
env_file:
*env
expose:
- "9000"
init: true
volumes: &php-volumes
- some volumes............
networks:
mmc-network:
aliases:
- mmc.php
# mysql - database
mysql:
build:
context: ./docker-config/mysql
dockerfile: ./Dockerfile
cap_add:
- SYS_NICE # CAP_SYS_NICE
env_file:
*env
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
init: true
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql
- ./db-seed/:/docker-entrypoint-initdb.d
networks:
- MMC-network
# redis - key/value database for caching & php sessions
redis:
build:
context: ./docker-config/redis
dockerfile: ./Dockerfile
expose:
- "6379"
init: true
networks:
- mmc-network
# webpack - frontend build system
webpack:
build:
context: ./docker-config/node-dev-webpack
dockerfile: ./Dockerfile
env_file:
*env
init: true
ports:
- "8080:8080"
volumes:
- some volumes..........
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
ports:
- "4444:4444"
volumes:
- ./cms:/data
build:
context: ./docker-config/selenium
dockerfile: ./Dockerfile
networks:
mmc-network:
aliases:
- mmc.selenium
volumes:
db-data:
cpresources:
storage:
networks:
mmc-network:
acceptance.suite.dist.yml:
actor: AcceptanceTester
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Recorder
modules:
error_level: "E_ALL"
enabled:
- WebDriver:
url: 'http://mmc.nginx'
host: mmc.selenium
port: '4444'
window_size: 1920x1200
browser: 'chrome'
wait: 60
capabilities:
os: Windows
os_version: 10
browserstack.local: true
- \Helper\Acceptance
NavigationCept.php
<?php
$I = new AcceptanceTester($scenario);
# define purpose of the test
$I->wantTo("check that navigation is functional.");
# check all menu items
$I->amOnPage('/');
$I->see('Search');
***Now, point to be noted, Codeception is already installed inside my PHP container and working perfectly.
When I try to run the test, I get the below error which indicates that the connection to my host (which is my Nginx server) has been refused.
I tried with a different url, for example, https://google.com and it just connected fine and everything was successful. Am I doing something wrong in here? Is my url param incorrect? Please help me out if you can. Thanks in advance.
I have seen such exception earlier with Codeception + Selenium. I do not have that project config file to share with you though.
My strong guess here is this error could be due to conflicts around Codeception-ChromeDriver-Selenium versions
Have you tried to execute this on a lower ChromeDriver version say 80 or 75?
Or change the Selenium version?
You could review the following notes which may help you debug this more
https://github.com/Codeception/Codeception/issues/5062
https://stackoverflow.com/a/63760572/2923098
Will update this answer if I find other resources to resolve this.
Docker service are reachable from each other using the service name as hostname. So your configuration could be:
enabled:
- WebDriver:
url: 'http://nginx'
host: selenium
port: '4444'
An alias to a service could be specified at another service as:
selenium:
links:
- "nginx:mmc.nginx"
Then the url could be url: 'http://mmc.nginx'
Workaround: use service IP address
enabled:
- WebDriver:
url: 'http://172.18.0.3'
host: 172.18.0.2
port: '4444'
Test setup using busybox:
docker-compose.yaml that runs 2 dummy web servers with netcat utility for demonstration purposes.
version: '3.7'
services:
nginx:
container_name: mmc-nginx
hostname: mmc-nginx
image: busybox
command: ["sh", "-c", "while true ; do (echo -e 'HTTP/1.1 200 OK\r\nConnection: Close\r\nContent-type: application/xml\r\n\r\n'; echo 'response from '`hostname`':80') | nc -l -p 80 ;done" ]
init: true
ports:
- "8000:80"
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
hostname: mmc-selenium
command: ["nc", "-l", "-p", "4444"]
ports:
- "4444:4444"
image: busybox
networks:
- mmc-network
networks:
mmc-network:
name: mmc-network
test command:
docker exec -it mmc-selenium wget -q "http://mmc-nginx" -O -
docker exec -it mmc-selenium wget -q "http://172.18.0.3" -O -
Response:
response from mmc-nginx:80
Access from outside docker network:
wget -q "http://localhost:8000" -O -
response from mmc-nginx:80
Ping to mmc-nginx
docker exec -it mmc-selenium ping -c2 mmc-nginx
PING mmc-nginx (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.071 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.111 ms
--- mmc-nginx ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.071/0.091/0.111 ms
Find service IP address:
Using docker. Change svc value accordingly.:
svc='friendly_solomon' docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$svc"
Using jq. Change svc value accordingly. jq is a great json processing tool to have btw.
svc='mmc-nginx'; docker network inspect bridge | jq -r --arg svc "$svc" '.[] | .Containers | .[] | select(.Name == $svc) | .IPv4Address'
Using grep
svc='mmc-nginx' docker network inspect bridge | grep -A5 "$svc" | grep 'IPv4Address

Docker, changing service name from PHP to different returns 503 Service Unavailable

I have docker-compose.yml which looks like this.
version: "3.6"
services:
php:
build: './php/'
ports:
- 9000:9000
networks:
- backend
volumes:
- .\puppet_projects\pname\pname:/var/www/html/pname
apache_pname:
build: './apache/'
depends_on:
- php
ports:
- "80:80"
networks:
- frontend
- backend
volumes:
- .\puppet_projects\pname\pname:/var/www/html/pname
networks:
frontend:
backend:
And when I am starting docker-compose up project works properly but after changing php to ie. php_pname I am receiving 503 Site Unavailable
version: "3.6"
services:
php_pname:
build: './php/'
ports:
- 9000:9000
networks:
- backend
volumes:
- .\puppet_projects\pname\pname:/var/www/html/pname
apache_pname:
build: './apache/'
depends_on:
- php_pname
ports:
- "80:80"
networks:
- frontend
- backend
volumes:
- .\puppet_projects\pname\pname:/var/www/html/pname
networks:
frontend:
backend:
What couses error. How can I fix it? Do I have to set up service name to php without changing it?
I suppose you use Apache2 as a proxy and it's configured to pass requests to php service. When you change the service name, it's internal DNS record in Docker changes as well and so Apache is unable to find php anymore.
You can either reflect the change in Apache configuration or add an alias to the php service to give it a second name:
services:
php_pname:
build: './php/'
ports:
- 9000:9000
networks:
backend:
aliases:
- php
This way you can access service php_pname from backend network with both php_pname and php.

Categories