Closed5

使い捨て MySQL 環境

7kaji7kaji

# 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)
7kaji7kaji
$ 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)
7kaji7kaji

追記

pull 時、platform 指定が必要 (👆でやっていたID指定しなくてもおk)

# Docker Image を pull
$ docker pull mysql:8.0.28 --platform linux/amd64

# コンテナを起動
$ docker run -it --rm --platform linux/amd64 \
       --privileged=true \
       --publish="127.0.0.1:3306:3306" \
       --expose="3306" \
       --volume "mysql-server-8-data:/var/lib/mysql" \
       --name="mysqld" \
       --env 'MYSQL_ALLOW_EMPTY_PASSWORD=1' \
       -d \
       mysql:8.0.28
$ docker exec -it mysqld mysql
or
$ mysql -uroot -h127.0.0.1
7kaji7kaji

Apple Silicon対応の、Docker公式の MySQL イメージができたらしい
https://hub.docker.com/r/arm64v8/mysql

$ docker run --name arm64v8-mysqld --privileged=true --publish="127.0.0.1:3306:3306" --expose="3306" --volume "arm64v8-mysql-server-8-data:/var/lib/mysql" --env 'MYSQL_ALLOW_EMPTY_PASSWORD=1' -d arm64v8/mysql:oracle
$ docker exec -it mysqld mysql
or
$ mysql -uroot -h127.0.0.1
このスクラップは2023/04/06にクローズされました