Case - Genbrug af en allerede oprettet Docker-volumen
Hvis du stopper Sejl med sail down
, forbliver datavolumen på Docker-værten uden at blive slettet.
Når Sail er stoppet, skal du bruge sail down -v
for at slette de eksisterende Docker-volumendata.
Første sail up
, DB_DATABASE=smed
Første gang du starter Sail, oprettes en volumen på Docker-værten.
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 |
Men når jeg afslutter Sail, slettes Docker-beholderen, men volumen slettes ikke.
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
Anden sail up
, DB_DATABASE=test
Hvis du starter en anden Sail i det samme mappenavn, vil den allerede oprettede Docker-volumen blive genbrugt.
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
Da data findes i test_sailmysql
, som er den volumen, der blev oprettet i den første kørsel, udføres en ny databaseoprettelsesopgave ikke.
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')
Start efter sletning af den eksisterende diskenhed
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
muligheder
sail down -h
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.