在本地机器上运行的django无法连接到运行MYSQL的Docker容器
大家好,所以我试图在我的本地机器上运行Django来连接到运行mysql的docker容器,但试图通过pip安装mysqlclient时不断收到错误。 首先我试图安装mysqlclient
时出现这个错误:
Collecting mysqlclient Using cached mysqlclient-1.3.12.tar.gz Complete output from command python setup.py egg_info: /bin/sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup.py", line 17, in <module> metadata, options = get_config() File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 44, in get_config libs = mysql_config("libs_r") File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 26, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) OSError: mysql_config not found
然后我继续通过brew安装mysql-connector-c
。 我reran pip install mysqlclient
,现在我得到这个错误:
Collecting mysqlclient Using cached mysqlclient-1.3.12.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup.py", line 17, in <module> metadata, options = get_config() File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in get_config libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')] File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in <listcomp> libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')] File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 12, in dequote if s[0] in "\"'" and s[0] == s[-1]: IndexError: string index out of range
有没有人遇到错误,当试图在localmachine上运行Django时,连接到docker容器中运行的MySQL?
在使用macOS时,请尝试下面的代码:
brew remove mysql-connector-c brew install mysql pip3 install mysqlclient
这将为你工作。
- Docker continuum / miniconda3容器不显示“conda”
- docker工人组成Django和节点
- Docker撰写无法为postgresql和redis创build容器
- 在docker-compose中使用network_mode ='host'break run:主机typesnetworking不能与链接一起使用
- Django的docker容器无法连接到MySQL容器,错误“无法连接到'db'(111)上的MySQL服务器”)
- 在Amazon Elastic Beanstalk上使用Docker部署Django
- configurationNGINX以正确地将URL转发到Graphite docker映像
- Djangodocker与本地卷
- 如何在Docker容器中连接外部mysql服务器