-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mount data files of database to local
- Loading branch information
Showing
3 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
# Database file | ||
*.db | ||
.data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eux | ||
|
||
# Launch a MySQL container and expose the port 3306 to the localhost. | ||
# A `todolist` database is created in the MySQL container if it does not exist. | ||
|
||
IMAGE_NAME=mysql | ||
CONTAINER_NAME=todolist-mysql | ||
DATA_DIR=$PWD/.data | ||
PORT=3306 | ||
MYSQL_ROOT_PASSWORD=root | ||
|
||
# If the .data directory does not exist, create it. | ||
if [ ! -d .data ]; then | ||
mkdir .data | ||
fi | ||
# If the container does not exist, create it. | ||
if ! docker ps -a | grep $CONTAINER_NAME; then | ||
docker run \ | ||
-dp $PORT:3306 \ | ||
-v "$DATA_DIR":/var/lib/mysql \ | ||
--name "$CONTAINER_NAME" \ | ||
-e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWORD" \ | ||
"$IMAGE_NAME" | ||
fi | ||
# If the `todolist` database does not exist, create it. | ||
docker exec -it "$CONTAINER_NAME" \ | ||
mysql -uroot -p$MYSQL_ROOT_PASSWORD \ | ||
-e "CREATE DATABASE todolist;" |
This file was deleted.
Oops, something went wrong.