Don't use the same database in development. I don't see any good reason why would you.
Two Laravel projects with sail on hitting the same db problem
So I managed to set the docker compose file on both projects to read/write in the same db by configuring docker-compose.yml files like this.
project1
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
- shared
mariadb:
image: 'mariadb:10'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmariadb:/var/lib/mysql'
networks:
- shared
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
shared:
external:
name: shared
volumes:
sailmariadb:
driver: local
project2:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
- shared
networks:
sail:
driver: bridge
shared:
external:
name: shared
and I created network called shared in docker networks. Bare in mind that on a project2 I added APP_PORT=81 so it doesn't get any conflicts
Started migration and seeds. added dd('project1') and dd('project2') on both project api.php routes file and when I test in postman or browser by sending request to localhost:80 or localhost:81 it displays correctly. Also I compared in both projects via tinker are they reading from the same database, and results were the same, so they are reading from the same db.
I remove the dd's and run sail artisan passport:install command on project2 and copy the secrets to .env it went well, still can open the localhost:80 and 81. And now here comes the problem.
When I send a request on postman after that to login endpoint it runs to infinity. I stop the request and when I try to again test localhost:81 I can't open it anymore, it runs to infinity. Even when I do sail down on both projects and try to up it again, same problem.
And I know that projects code isn't a problem since I run it on remote server. Any ideas what should I do next to make it work.
Please or to participate in this conversation.