Skip to content

Instantly share code, notes, and snippets.

@astrsk-hori
Last active October 11, 2017 01:19
Show Gist options
  • Save astrsk-hori/ff51ab49004ebbfe1af9 to your computer and use it in GitHub Desktop.
Save astrsk-hori/ff51ab49004ebbfe1af9 to your computer and use it in GitHub Desktop.
docker pull mysql
docker run --name mysql -e MYSQL_ROOT_PASSWORD=mysql -d -p 3306:3306 mysql
# 接続確認 passwordはmysqlになります。
mysql -h $(boot2docker ip) -uroot -p
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5edc5732d78 mysql:latest "/entrypoint.sh mysq 49 minutes ago Up 33 minutes 0.0.0.0:3306->3306/tcp mysql
$ docker exec -it e5edc5732d78 bash
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
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>
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5edc5732d78 mysql:latest "/entrypoint.sh mysq 49 minutes ago Up 33 minutes 0.0.0.0:3306->3306/tcp mysql
# 停止
docker stop e5edc5732d78
# 削除
docker rm e5edc5732d78
docker pull busybox
# 永続化のためのデータ領域を作成
docker run -v /var/lib/mysql --name mysql_data busybox
docker run --volumes-from mysql_data --name mysql -e MYSQL_ROOT_PASSWORD=mysql -d -p 3306:3306 mysql
docker run --name NAME -h HOSTNAME --volumes-from mysql_data --link mysql:ALIAS_MYSQL -i -t -d HOGE_APP
mysql -h ALIAS_MYSQL -uroot -p
mysql -h ALIAS_MYSQL -uroot -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment