Sprawa — ponowne użycie już utworzonego woluminu Dockera
Jeśli zatrzymasz Sail za pomocą sail down
, wolumen danych pozostaje na hoście platformy Docker bez usuwania.
Gdy Sail jest zatrzymany, użyj sail down -v
aby usunąć istniejące dane woluminu Docker.
Pierwszy sail up
, DB_DATABASE=forge
Kiedy po raz pierwszy uruchamiasz Sail, na hoście Dockera tworzony jest wolumen.
grep DB_DATABASE .env
DB_DATABASE=forge
docker volume ls
DRIVER VOLUME NAME
sail up -d
Creating network "test_sail" with driver "bridge"
Creating volume "test_sailmysql" with local driver
Creating volume "test_sailredis" with local driver
Creating test_mailhog_1 ... done
Creating test_mysql_1 ... done
Creating test_redis_1 ... done
Creating test_laravel.test_1 ... done
docker volume ls
DRIVER VOLUME NAME
local test_sailmysql
local test_sailredis
sail mysql
mysql> show databases;
| forge |
Jednak po wyjściu z Sail kontener Docker jest usuwany, ale wolumin nie jest usuwany.
sail down
Stopping test_laravel.test_1 ... done
Stopping test_mailhog_1 ... done
Stopping test_redis_1 ... done
Stopping test_mysql_1 ... done
Removing test_laravel.test_1 ... done
Removing test_mailhog_1 ... done
Removing test_redis_1 ... done
Removing test_mysql_1 ... done
Removing network test_sail
docker volume ls
DRIVER VOLUME NAME
local test_sailmysql
local test_sailredis
Drugi sail up
, DB_DATABASE=test
Jeśli uruchomisz drugi Sail w tej samej nazwie katalogu, już utworzony wolumin Dockera zostanie ponownie wykorzystany.
grep DB_DATABASE .env
DB_DATABASE=test
sail up -d
Creating network "test_sail" with driver "bridge"
Creating test_mysql_1 ... done
Creating test_redis_1 ... done
Creating test_mailhog_1 ... done
Creating test_laravel.test_1 ... done
docker volume ls
DRIVER VOLUME NAME
local test_sailmysql
local test_sailredis
Ponieważ dane istnieją w test_sailmysql
, czyli wolumen utworzony przy pierwszym uruchomieniu, nowe zadanie tworzenia bazy danych nie jest wykonywane.
sail mysql
ERROR 1049 (42000): Unknown database 'test'
sail artisan migrate
Illuminate\Database\QueryException
SQLSTATE[HY000] [1049] Unknown database 'test' (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')
Rozpocznij po usunięciu istniejącego woluminu
sail down -v
...
Removing volume test_sailmysql
Removing volume test_sailredis
sail up -d
...
Creating volume "test_sailmysql" with local driver
Creating volume "test_sailredis" with local driver
sail mysql
mysql> show databases;
| test |
sail artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (214.30ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (99.56ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (151.61ms)
sail down
opcje
sail down -h
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.