Open2

使い捨て MySQL 環境


# M1 Mac だとまだむり?
$ docker pull mysql:8.0.23
8.0.23: Pulling from library/mysql
no matching manifest for linux/arm64/v8 in the manifest list entries

# ID 指定すればいける
$ docker pull mysql@sha256:43bf7db32d11e75d8463a8bc077f09af5fb5b84b182b1d74124ddca633093bfa

# TAG が <none> になっちゃう
$ docker images
REPOSITORY                                          TAG          IMAGE ID       CREATED         SIZE
mysql                                               <none>       c8562eaf9d81   2 months ago    546MB

# TAG に名前つけておく
$ docker tag c8562eaf9d81 mysql:8.0.23

# TAG 設定されるはず
$ docker images
REPOSITORY                                          TAG          IMAGE ID       CREATED         SIZE
mysql                                               8.0.23       c8562eaf9d81   2 months ago    546MB

# --platform 指定しないとダメ
$ docker run --platform linux/amd64 --name mysql8 -e MYSQL_ROOT_PASSWORD=wa9wa9 -d --rm mysql:8.0.23
26ddde009c33a06de022ed560a10bab26fbea75b92c30d0cd4fa4c2558d125a9

# 起動確認
$ docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS         PORTS                               NAMES
26ddde009c33   mysql:8.0.23                  "docker-entrypoint.s…"   11 seconds ago   Up 9 seconds   3306/tcp, 33060/tcp                 mysql8

# MySQL 接続
$ docker exec -it mysql8 mysql -uroot -pwa9wa9
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> select version() as mysql_version;
+---------------+
| mysql_version |
+---------------+
| 8.0.23        |
+---------------+
1 row in set (0.00 sec)
$ docker pull mysql:8.0.25 --platform linux/x86_64

$ docker images |grep mysql
mysql                         8.0.25       c0cdc95609f1   5 weeks ago     556MB

$ docker run --platform linux/amd64 --name mysql8 -e MYSQL_ROOT_PASSWORD=wa9wa9 -d --rm mysql:8.0.25

$ docker ps |grep mysql
3dc6c0487ed4   mysql:8.0.25             "docker-entrypoint.s…"   23 seconds ago   Up 22 seconds                   3306/tcp, 33060/tcp

$ docker exec -it mysql8 mysql -uroot -pwa9wa9
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>  select version() as mysql_version;
+---------------+
| mysql_version |
+---------------+
| 8.0.25        |
+---------------+
1 row in set (0.00 sec)
ログインするとコメントできます