I have one container running "dockerfile/mysql" which I can connect to and interact with. I'm trying to build another image for a Python application that will read from a mysql db. The problem is that the Python app requires MySQL-python and attempts to install it on setup. Because this container does not hold the mysql server, i end up with;
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/tmp/pip_build_vagrant/MySQL-python/setup.py) egg_info for package MySQL-python
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_vagrant/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found
which is fully understandable.
How should i set up my Python app container (which is using SQLAlchemy) to read from the mysql container?
Thanks
Add apt-get install -y libmysqlclient-dev
to your Dockerfile
.
If you use python:3.5-alpine
, you can install mysqlclient
by adding following code into your Dockerfile
:
RUN set -e; \
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
linux-headers \
mariadb-dev \
python3-dev \
postgresql-dev \
;
The whole Dockerfile
will be like this:
# Version: 0.0.1
FROM python:3.5-alpine
ENV PYTHONUNBUFFERED 1
RUN set -e; \
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
linux-headers \
mariadb-dev \
python3-dev \
postgresql-dev \
;
RUN mkdir /djcode
WORKDIR /djcode
ENV REFRESHED_AT 2017-12-25
ADD requirements.txt /djcode/
RUN pip install --no-cache-dir -r /djcode/requirements.txt
RUN pip install uwsgi
ADD . /djcode/
EXPOSE 6001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With