请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

在容器中无法进入mysql

图片描述

[vagrant@docker-node1 ~]$ docker image ls
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
makchikin/flask-redis   latest              0218f147cf9d        24 hours ago        891MB
redis                   latest              dcf9ec9265e0        4 days ago          98.2MB
python                  2.7                 e8cff83571c6        4 days ago          886MB
mysql                   5.7                 1e4405fe1ea9        4 days ago          437MB
nginx                   latest              231d40e811cd        4 days ago          126MB
busybox                 latest              020584afccce        3 weeks ago         1.22MB
[vagrant@docker-node1 ~]$ sudo docker run -d -v mysql:/var/lib/mysql --name mysql1 -e MYSQL_ALLOW_EMPIT_PASSWORD=true mysql:5.7
fd0afe7906f4ff5a34be8b78ba4d4e41850ff1da429787afa1587cb23ca43422
[vagrant@docker-node1 ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
fd0afe7906f4        mysql:5.7           "docker-entrypoint.s…"   6 seconds ago       Exited (1) 4 seconds ago                       mysql1
[vagrant@docker-node1 ~]$ docker rm mysqlq
Error: No such container: mysqlq
[vagrant@docker-node1 ~]$ docker rm mysql1
mysql1
[vagrant@docker-node1 ~]$ docker volume rm mysql
mysql
[vagrant@docker-node1 ~]$ sudo docker run -d -it --name mysql1 -v mysql:/var/lib/mysql -e MYSQL_ALLOW_EMPIT_PASSWORD=true mysql:5.7 /bin/bash
25aa375b46d221c407bab67761318248c9c959c21e2ed75660def5991ef8491e
[vagrant@docker-node1 ~]$ docker exec -it mysql1 /bin/bash
root@25aa375b46d2:/# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@25aa375b46d2:/# ps aux |grep mysql
bash: ps: command not found
root@25aa375b46d2:/# musql
bash: musql: command not found
root@25aa375b46d2:/# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@25aa375b46d2:/# sudo service mysql start
bash: sudo: command not found
root@25aa375b46d2:/# 

老师您好,我安装您的视频一直操作,如果按照视频里面的命令,

[vagrant@docker-node1 ~]$ sudo docker run -d -v mysql:/var/lib/mysql --name mysql1 -e MYSQL_ALLOW_EMPIT_PASSWORD=true mysql:5.7
54af2087b120bb802dd0ae1e899fa966ac44921fc767f1787addc1031df4a8a8
[vagrant@docker-node1 ~]$ sudo docker exec -it mysql1 /bin/bash
Error response from daemon: Container 54af2087b120bb802dd0ae1e899fa966ac44921fc767f1787addc1031df4a8a8 is not running

容器一运行就关闭了,并且报错,所以我改成了交互式创建和运行容器

sudo docker run -d -it --name mysql1 -v mysql:/var/lib/mysql -e MYSQL_ALLOW_EMPIT_PASSWORD=true mysql:5.7 /bin/bash
[vagrant@docker-node1 ~]$ docker exec -it mysql1 /bin/bash
root@25aa375b46d2:/# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@25aa375b46d2:/# ps aux |grep mysql
bash: ps: command not found

但是我一直进不去容器里面的mysql,进入容器里面也没有找到 mysql 有进程在运行,请问这是什么原因导致的呢?谢谢!

正在回答

1回答

sudo docker run -d -it --name mysql1 -v mysql:/var/lib/mysql -e MYSQL_ALLOW_EMPIT_PASSWORD=true mysql:5.7 /bin/bash  这个不是启动mysql容器的方法。https://hub.docker.com/_/mysql 

$ docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
0fe1edd0538fed6a06bce20dcdf5e5467c3b522515f558e76cb10c4d986130cb
$ docker exec -it some-mysql sh
#
#
#
# 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.7.24 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>


0 回复 有任何疑惑可以回复我~
  • 提问者 MakChiKin #1
    可以进入mysql了,谢谢老师!
    回复 有任何疑惑可以回复我~ 2019-11-28 11:40:47
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信