DATABASE docker-compose.yml
version: "3.8"
services:
db:
image: mysql:5.7
container_name: app-database
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/secrets:/run/secrets
- data:/var/lib/mysql
networks:
- sky-net
networks:
sky-net:
external: true
volumes:
data:
external: true
name: domain_data
APP 1 docker-compose.yml
( The image jonwiz/php73-fpm-laravel is my custom Dockerfile built on top of php7.3-fpm from docker hub. )
version: "3.8"
services:
app:
image: jonwiz/php73-fpm-laravel:${PROJECT_TAG}
container_name: website1-app
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- net
- sky-net
nginx:
image: nginx:latest
container_name: website1-nginx
ports:
- ${PROJECT_PORT}:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- net
networks:
net:
driver: bridge
sky-net:
external: true
APP 2 docker-compose.yml
version: "3.8"
services:
app:
image: jonwiz/php73-fpm-laravel:${PROJECT_TAG}
container_name: website2-app
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- net
- sky-net
nginx:
image: nginx:latest
container_name: website2-nginx
ports:
- ${PROJECT_PORT}:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- net
networks:
net:
driver: bridge
sky-net:
external: true
LARAVEL .env db config
Both website applications use the same DB config to connect to db service on sky-net
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=my-database
DB_USERNAME=username
DB_PASSWORD=password
NGINX website config ( both websites use identical nginx conf )
server {
listen 80;
index index.php;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/src/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
error_page 404 /index.php;
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;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location = /favicon.ico {access_log off; log_not_found off;}
location = /robots.txt {access_log off; log_not_found off;}
location ~ /\.(?!well-known).* {
deny all;
}
}
So since I’ve set this up, it appears to be working, as far as sharing the same sky-db network and app-database container with db service.
However the laravel_session cookies are competing with eachother. I login with one browser tab, the other logs out. I want to be able to keep the cookies separate and authenticate with both websites at the same time.
This way I can test multiple users logged in at the same time with same browser.
Maybe it’s a laravel config to override cookie name, and specify the port.
Since website1 is on localhost/ and website2 is on localhost:81
When one website is logged in, the other gets logged out and vice versa.
I think I have to setup nginx reverse proxy for my local development, to route domains to different containers.
I have nginx setup on my production host, but not on my local ubuntu 22.04 dev host.
So I believe using different domains will ensure my cookies don’t collide, and I can test the sites using different domains.