Did
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' c7332b9fc167
Then got the ip address and used it for the migrations
sail artisan migrate --database=mysql_backup
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.28.0.5' (using password: NO) (SQL: select * from information_schema.tables where table_schema = backup and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
+36 vendor frames
37 artisan:35
Illuminate\Foundation\Console\Kernel::handle()
➜ ~/code/smart48.com git:(sail) ✗ sail artisan migrate --database=mysql_backup
INFO Preparing database.
Creating migration table ............................................................................................................... 21ms DONE
INFO Loading stored database schemas.
database/schema/mysql_backup-schema.dump .............................................................................................. 205ms DONE
Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'backup.migrations' doesn't exist (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
i A table was not found: You might have forgotten to run your database migrations.
https://laravel.com/docs/master/migrations#running-migrations
+27 vendor frames
28 artisan:35
Illuminate\Foundation\Console\Kernel::handle()
But you can also use the container name so
DB_PUBLISH_HOST=smart48com-mysql-1
which you can locate using docker ps
And to use sail mysql bash with ease and for all databases I decided to use one database container but just added three databases to the shell file to load
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
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
depends_on:
- mysql
- redis
- mailpit
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './docker/all-databases.sh:/docker-entrypoint-initdb.d/10-create-backup-database.sh'
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:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s
mailpit:
image: 'axllent/mailpit:latest'
ports:
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
sail-redis:
driver: local
You can see - './docker/all-databases.sh:/docker-entrypoint-initdb.d/10-create-backup-database.sh' where I load all database bases in using
#!/usr/bin/env bash
mysql --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL
CREATE DATABASE IF NOT EXISTS testing;
GRANT ALL PRIVILEGES ON \`testing%\`.* TO '$MYSQL_USER'@'%';
CREATE DATABASE IF NOT EXISTS smart48_publish_db;
GRANT ALL PRIVILEGES ON \`smart48_publish_db%\`.* TO '$MYSQL_USER'@'%';
CREATE DATABASE IF NOT EXISTS backup;
GRANT ALL PRIVILEGES ON \`backup%\`.* TO '$MYSQL_USER'@'%';
EOSQL