I've been away from Laravel development for a while. Too long, sadly. A lot of other, higher priority items, kept me away. While I was developing, I was using a Docker environment and I would use sail up to get all my containers running and then php artisan serve to get my site up. It was using the default address of 127.0.0.1:8000. Everything worked. But now, and I'm not at all sure why, it doesn't. Run I run sail artisan serve on my local machine (as opposed to site.server container), if I try to navigate to the page I'm usually told "Connection Refused". Sometimes if I run it from the command line using php artisan serve, I can get it to respond but as with the other method, I'm usually told "Connection Refused".
To add insult to injury, on those few occasions I am able to get it to respond, when I try to do anything that involves the database, I'm given an error saying that it couldn't connect. But I find that odd because if I boot up php artisan tinker, (or sail, depending on where I'm running the command), I can interact with the database no problem. User::all() does exactly what it should be doing.
I've searched around for possible answers but I'm at my wits end. I'm hoping that some of y'all can give me some suggestions as to where in my codebase (or for docker) I should focus to try to fix the problem.
I'm running:
Docker 4.11.1
Laravel Framework 9.23.0
This is my docker-compose.yml file:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
site.server:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
XDEBUG: '${XDEBUG}'
XDEBUG_PORT: '${XDEBUG_PORT}'
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:-develop,debug}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
PHP_IDE_CONFIG: serverName=Docker
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_USER: '${DB_USERNAME}'
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_ALLOW_EMPTY_PASSWORD: 0
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}" ]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
retries: 3
timeout: 5s
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
And then here is a portion of my .env file:
APP_NAME=communal-haven
APP_ENV=local
APP_KEY=BLAH_BLAH_BLAH
APP_DEBUG=true
APP_URL=http://communal-haven.test
APP_SERVICE="site.server"
XDEBUG=true
XDEBUG_PORT=9003
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
FORWARD_DB_PORT=3306
DB_DATABASE=communal_haven
DB_USERNAME=MY_UID
DB_PASSWORD=MY_PASSWORD
Thank you for any help and/or suggestions.
Christoph