Install python3 mysql driver mysqlclient on alpine linux.
- Total size 101 MB, compressed size 34 MB
- Why mysqlclient ? Answers on stackoverflow
First, a mariadb container named my-mariadb is running.
>> docker ps
d627912ec946 mariadb "docker-entrypoint..." 6 days ago Up 6 days 0.0.0.0:3306->3306/tcp my-mariadb
Run this mysqlclient driver linked with my-mariadb.
docker run -it --link my-mariadb:mysql py3-mysqlclient-alpine python
Python 3.6.1 (default, Jun 19 2017, 23:58:41)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.connect(host="mysql", user="YOUR USER", passwd="YOUR PASSWORD", db="YOUR DATABASE NAME")
<_mysql.connection open to 'mysql' at 55f032a2bbb8>
- For more info about
--link
https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#communication-across-links - Some examples about MySQLdb https://github.com/PyMySQL/mysqlclient-python/blob/master/doc/user_guide.rst#some-examples
In most cases, you will build your own image based on this.