使用docker ps命令查看本地容器的启用情况,确认有我刚创建的容器esofar-mysql。
esofar@ubuntu:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a182d96cb996 mysql "docker-entrypoint.s…" 18 minutes ago Up 18 minutes 3306/tcp, 33060/tcp esofar-mysql命令docker exec允许您在 Docker 容器内运行命令。如下命令会在esofar-mysql容器中为您提供一个 bash shell:
docker exec -it esofar-mysql bash输入mysql -u root -p,然后键入密码就连接上mysql服务了。
esofar@ubuntu:~$ docker exec -it esofar-mysql bash root@a182d96cb996:/# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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>exit退出 mysql 连接,exit退出容器。