[英]Can't connect from docker using mysqlclient
I'm trying to connect to my mysql container but whenever I try to run mysql -uroot -p
I always get bash: mysql: command not found
but mysql is already installed in the docker container when I try to run pip3 freeze
I get this result 我正在尝试连接到我的mysql容器,但是每当我尝试运行
mysql -uroot -p
我总是会收到bash: mysql: command not found
但是当我尝试运行pip3 freeze
时pip3 freeze
容器中已经安装了mysql,我得到了结果
alembic==0.9.6
appdirs==1.4.3
bcrypt==3.1.4
certifi==2017.11.5
cffi==1.11.2
chardet==3.0.4
click==6.7
elasticsearch==5.5.1
flasgger==0.8.0
Flask==0.12.2
Flask-Cors==3.0.3
gevent==1.2.2
greenlet==0.4.12
idna==2.6
iso3166==0.8
itsdangerous==0.24
Jinja2==2.10
jsonschema==2.6.0
Mako==1.0.7
MarkupSafe==1.0
mistune==0.8.3
mock==2.0.0
mysqlclient==1.3.12
packaging==16.8
pbr==3.1.1
pybuilder==0.11.12
pycparser==2.18
pycrypto==2.6.1
pyparsing==2.2.0
python-dateutil==2.6.1
python-editor==1.0.3
PyYAML==3.12
redis==2.10.6
requests==2.18.4
six==1.11.0
SQLAlchemy==1.2.0
tblib==1.3.2
ujson==1.35
urllib3==1.21.1
validate-email==1.3
Werkzeug==0.13
As you can see mysqlclient is installed. 如您所见,已安装mysqlclient。 If I try to check if mysql container is accessible inside my docker using ping.
如果我尝试使用ping检查mysql容器是否可在docker内部访问。 It's working properly and I was able to get a response.
它工作正常,我得到了回应。 How do I connect now since it says
bash: mysql: command not found
我现在如何连接,因为它说
bash: mysql: command not found
-- UPDATE -- -更新-
After running docker run I connected inside the docker container and run pip install --no-cache-dir -r requirements.txt
and below is the output 运行docker run之后,我连接到docker容器内部并运行
pip install --no-cache-dir -r requirements.txt
,下面是输出
Now it says requirement already satisfied. 现在它说要求已经满足了。 I'm not sure but does this mean it already installed the package?
我不确定,但这是否意味着它已经安装了软件包? Below is my dockerfile
以下是我的dockerfile
FROM python:3.5.2
ADD deployment /root/.ssh
RUN chmod 700 /root/.ssh/id_rsa
RUN ssh-keyscan -t rsa bitbucket.org > /root/.ssh/known_hosts
RUN mkdir -p /app
ADD . /app
WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt
WORKDIR /app/myproject
CMD ["python", "./init.py", "-c", "config/config.yaml"]
The problem here is that the CLI command mysql
is not installed on your HOST machine. 这里的问题是您的HOST计算机上未安装CLI命令
mysql
。 It is most likely installed inside your docker container however. 但是,它很可能安装在您的docker容器中。 As one of the comments pointed out, the
mysqlclient
you installed with pip
would NOT install the mysql
command line tool. 正如评论中指出的那样,使用
pip
安装的mysqlclient
不会安装mysql
命令行工具。
As a quick workaround, I would suggest running the mysql
command INSIDE your mysql container, like so: 作为一种快速的解决方法,我建议在mysql容器中运行
mysql
命令,如下所示:
docker exec -it <container id> mysql -u root -h localhost -p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.