Case - Menggunakan kembali volume Docker yang sudah dibuat
Jika Anda menghentikan Sail dengan sail down
, volume data tetap berada di host Docker tanpa dihapus.
Saat Sail dihentikan, gunakan sail down -v
untuk menghapus data volume Docker yang ada.
sail up
, DB_DATABASE=tempa
Saat Anda pertama kali memulai Sail, volume dibuat di host Docker.
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 |
Namun, ketika saya keluar dari Sail, wadah Docker dihapus tetapi volumenya tidak dihapus.
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
sail up
, DB_DATABASE=tes
Jika Anda memulai Sail kedua dengan nama direktori yang sama, volume Docker yang sudah dibuat akan digunakan kembali.
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
Karena data ada di test_sailmysql
, yang merupakan volume yang dibuat saat pertama kali dijalankan, tugas pembuatan database baru tidak akan dijalankan.
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')
Mulai setelah menghapus volume yang ada
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
opsi
sail down -h
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.