Docker Hubからイメージを探す
自分で作りたいところだが、時間の関係もあるのでdocker searchコマンドでイメージを探す。
$ docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relati... 590 [OK] tutum/mysql MySQL Server image - listens in port 3306.... 110 [OK] orchardup/mysql 37 [OK] centurylink/mysql Image containing mysql. Optimized to be li... 21 [OK] wnameless/mysql-phpmyadmin MySQL + phpMyAdmin https://index.docker.io... 15 [OK] google/mysql MySQL server for Google Compute Engine 13 [OK] sameersbn/mysql 11 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 5 [OK] …以下省略
Dockerオフィシャルものを使おうかと思ったがMySQL社が提供しているmysql/mysql-server というのが2日前に上がっていたので今回はそちらを使うことにする。これだとoraclelinuxがベースになるようだ。
Docker pull
今回はデフォルトのlatestを使用。
$ docker pull mysql/mysql-server Pulling repository mysql/mysql-server 296ef3e8959e: Download complete 511136ea3c5a: Download complete ad98bd7101f2: Download complete 8f0a27825a9a: Download complete c94023a2b919: Download complete 92af7065aa1f: Download complete 37a5e5ad845c: Download complete 4e1a8f6dcb3c: Download complete 0b5ee168e81e: Download complete 51526e13d844: Download complete d8aaad0b8379: Download complete Status: Downloaded newer image for mysql/mysql-server:latest
確認
$ docker images |grep mysql mysql/mysql-server latest 296ef3e8959e 47 hours ago 295.3 MB
サービスの起動
後でMySQLWorkbenchからも接続したいので-pフラグをつけておく。
container_name とpassword,tagは適宜書き換える。
$ docker run --name <container_name> -e MYSQL_ROOT_PASSWORD=<password> -d -p 127.0.0.1:3306:3306 mysql/mysql-server:latest
確認
$ docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1818c284611 mysql/mysql-server:latest "/entrypoint.sh mysq 8 seconds ago Up 8 seconds 127.0.0.1:3306->3306/tcp study-mysql
コマンドラインからの接続
container_name とtagを適宜書き換える。
$ docker run -it --link <conteiner_name>:mysql --rm mysql/mysql-server:<tag> sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' 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 1 Server version: 5.6.24 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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>