対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 2018-06-27
- Docker 18.06.1-ce, build e68fc7a
- docker-compose 1.23.0dev, build 48a6f213
前提
- http://ytyaru.hatenablog.com/entry/2019/06/05/000000
- http://ytyaru.hatenablog.com/entry/2019/08/07/000000
- http://ytyaru.hatenablog.com/entry/2019/08/08/000000
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker-compose armhf 13e9175812a1 2 hours ago 1.05GB python 3.6 4af1ba713e0d 3 weeks ago 736MB
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
情報源
手順
- イメージのダウンロード
- 確認
- 起動
- CLI起動
1. イメージのダウンロード
docker pull jsurf/rpi-mariadb
数分後に完了。
... Status: Downloaded newer image for jsurf/rpi-mariadb:latest
2. 確認
イメージ一覧に表示される。
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker-compose armhf 13e9175812a1 2 hours ago 1.05GB jsurf/rpi-mariadb latest 66f523dae746 3 days ago 289MB python 3.6 4af1ba713e0d 3 weeks ago 736MB
3. 起動
情報源によると以下のコマンドで起動するらしい。
$ docker run --name コンテナ名 -e MYSQL_ROOT_PASSWORD=パスワード -d mariadb:タグ
以下のように適当に当てはめて実行。
$ docker run --name mariadb-gitea -e MYSQL_ROOT_PASSWORD=gitea -d mariadb:10.3.9
イメージが見つからないと怒られる。
Unable to find image 'mariadb:latest' locally latest: Pulling from library/mariadb docker: no matching manifest for unknown in the manifest list entries.
イメージ名を以下のように指定し直したら起動した。
$ docker run --name mariadb-gitea -e MYSQL_ROOT_PASSWORD=gitea -d jsurf/rpi-mariadb 8a52d56985d30e1e021c1fb59b801cad8d7f7f09bc45c14713bdb11905844150
起動中のコンテナに追加された。
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8a52d56985d3 jsurf/rpi-mariadb "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp mariadb-gitea
4. CLI起動
ターミナルでの対話ツールを起動する。
情報源は-uroot
とあったが誤字。正しくは-u root
。誤字多すぎ。
docker run -it --link mariadb-gitea:mysql --rm jsurf/rpi-mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -u root -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.0.36-MariaDB-0+deb8u1 (Raspbian) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> \h General information about MariaDB can be found at http://mariadb.org List of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments are db and host. delimiter (\d) Set statement delimiter. edit (\e) Edit command with $EDITOR. ego (\G) Send command to mysql server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. nopager (\n) Disable pager, print to stdout. notee (\t) Don't write into outfile. pager (\P) Set PAGER [to_pager]. Print the query results via PAGER. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file name as an argument. status (\s) Get status information from the server. system (\!) Execute a system shell command. tee (\T) Set outfile [to_outfile]. Append everything into given outfile. use (\u) Use another database. Takes database name as argument. charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. For server side help, type 'help contents'
一体これで何ができるの? ここを参考にしてみた。
MariaDB [(none)]> select last_insert_id(); +------------------+ | last_insert_id() | +------------------+ | 0 | +------------------+ 1 row in set (0.04 sec)
SQLが打てるっぽい。これならDBも作成できると思われる。