Docker を使って Windows 上に MySQL を立てる

予め Docker をインストールしておきます。詳細については割愛。

PowerShell で以下を実行すると MySQL が立ち上がって接続できます。

docker pull mysql
docker run --name mysql-sandbox -e MYSQL_ROOT_PASSWORD=mypass -d -p 3306:3306 mysql
docker exec -it mysql-sandbox mysql -p

停止/起動

docker stop mysql-sandbox
docker start mysql-sandbox

削除(docker stop しておく)

docker rm mysql-sandbox
docker rmi mysql

詳細

PS C:\Users\SnowCait> docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
5040bd298390: Pull complete
55370df68315: Pull complete
fad5195d69cc: Pull complete
a1034a5fbbfc: Pull complete
17f3570b42ae: Pull complete
6bf4b16e5339: Pull complete
9700c9731729: Pull complete
f2fea9c5b632: Pull complete
2f8101f5336d: Pull complete
0dc8f8a1031a: Pull complete
a1b9627588c7: Pull complete
Digest: sha256:5e2ec5964847dd78c83410f228325a462a3bfd796b6133b2bdd590b71721fea6
Status: Downloaded newer image for mysql:latest
PS C:\Users\SnowCait> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              7666f75adb6b        3 weeks ago         406 MB
PS C:\Users\SnowCait> docker run --name mysql-sandbox -e MYSQL_ROOT_PASSWORD=mypass -d -p 3306:3306 mysql
a05f65b894bc7c69f998f76ededcd22f290c76f64d3d9a7ff483081cc5a03f6d
PS C:\Users\SnowCait> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED                  STATUS              PORTS                    NAMES
a05f65b894bc        mysql               "docker-entrypoint..."   Less than a second ago   Up 11 seconds       0.0.0.0:3306->3306/tcp   mysql-sandbox
PS C:\Users\SnowCait> docker exec -it mysql-sandbox mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
 
mysql> create database sandbox;
Query OK, 1 row affected (0.00 sec)
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sandbox            |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
 
mysql> ^DBye
PS C:\Users\SnowCait> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED                  STATUS              PORTS                    NAMES
a05f65b894bc        mysql               "docker-entrypoint..."   Less than a second ago   Up 11 minutes       0.0.0.0:3306->3306/tcp   mysql-sandbox
PS C:\Users\SnowCait> docker stop mysql-sandbox
mysql-sandbox
PS C:\Users\SnowCait> docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
PS C:\Users\SnowCait> docker start mysql-sandbox
mysql-sandbox
PS C:\Users\SnowCait> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED                  STATUS              PORTS                    NAMES
a05f65b894bc        mysql               "docker-entrypoint..."   Less than a second ago   Up 2 seconds        0.0.0.0:3306->3306/tcp   mysql-sandbox
PS C:\Users\SnowCait> docker stop mysql-sandbox
mysql-sandbox
PS C:\Users\SnowCait> docker rm mysql-sandbox
mysql-sandbox
PS C:\Users\SnowCait> docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
PS C:\Users\SnowCait> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              7666f75adb6b        3 weeks ago         406 MB
PS C:\Users\SnowCait> docker rmi mysql
Untagged: mysql:latest
Untagged: mysql@sha256:5e2ec5964847dd78c83410f228325a462a3bfd796b6133b2bdd590b71721fea6
Deleted: sha256:7666f75adb6b50676a366c6fd7a3916cb41f6e8eaf336c3d3ab7d35317fed0b9
Deleted: sha256:49c3526d899ca5d1e6ad702a670560a436c9b02240c4bd37d6a1ddcbed015208
Deleted: sha256:0ce5aa0da9ebf98ecfb014f004a50bc46e30d9d2f5026e8ce1ef4090964e64af
Deleted: sha256:06dd4f9415b3f89d3fb1138623cebb7245affc9410611552c6fb52b091587a2e
Deleted: sha256:a1cef2e730afb041ed430d09a777deb9c18fe5cf16eecde3d794fa120fcdbd6a
Deleted: sha256:f70165b2970c60180d26f4879c5a1cdb8e07c50f620df14a46e97c4606645e75
Deleted: sha256:2c9fbf48ff4918308a642a8d64578963e794f55c3cc3c9bf0c6d00836f330e07
Deleted: sha256:0d339cb91245a1bfa388a5d04851944899dc15d40b8606b642141cb64c738c87
Deleted: sha256:a21109e3e82200607be69e06ccfd12b4213b5490f5fcb05f6cbdd6023cfb7427
Deleted: sha256:fbf20a39ee0b5cbe0a2a9c873ebac8603c134047c70e0078901c9c2bc54661b8
Deleted: sha256:f26bab3379dc11fa4d7f67768e33dad1e763a7950ebcbe0c4984656c17fe8429
Deleted: sha256:a2ae92ffcd29f7ededa0320f4a4fd709a723beae9a4e681696874932db7aee2c
PS C:\Users\SnowCait> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

カテゴリー: Docker タグ: パーマリンク