Dockerコンテナ(mysql)にアクセスする
起動中のコンテナを確認する
$docker-compose ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
847c99b0929c nginx:latest "nginx -g 'daemon of…" 20 minutes ago Up 20 minutes 0.0.0.0:8080->80/tcp docker_php_nginx_1
5e2039b237df docker_php_php "docker-php-entrypoi…" 20 minutes ago Up 20 minutes 9000/tcp docker_php_php_1
8193d899b38d phpmyadmin/phpmyadmin:latest "/docker-entrypoint.…" 20 minutes ago Up 20 minutes 0.0.0.0:8888->80/tcp docker_php_phpmyadmin_1
f4ff8b6b8ac3 mysql:5.7 "docker-entrypoint.s…" 22 minutes ago Up 20 minutes 33060/tcp, 0.0.0.0:13306->3306/tcp docker_php_db_1
ホストPCからコンテナ(mysql)に接続する
CONTAINER IDを指定
$docker exec -it f4ff8b6b8ac3 bash
mysqlに接続
root@f4ff8b6b8ac3:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.03 sec)