Custom OpenCPU Docker image prepared for connecting to a MySQL database instance.
docker build -t savvydatainsights/opencpu-mysql .
Bind mount an odbc.ini like the example:
[DSN]
Description=MySQL database
Driver=MySQL ODBC 8.0 Driver
SERVER=mysql
PORT=3306
DATABASE=data_analysis
UID=root
PWD=root
The Driver key must have the value MySQL ODBC 8.0 Driver, the name defined during the MySQL connection driver installation.
The other values must be set according to the connection parameters of your MySQL instance.
Run a MySQL Docker image:
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=data_analysis -p 3306:3306 -d mysql:8.0.15
Run the custom OpenCPU Docker image:
docker run --name opencpu --link mysql:mysql -v $(pwd)/odbc.ini:/etc/odbc.ini -p 8004:8004 -d savvydatainsights/opencpu-mysql
Enter into the OpenCPU container:
docker exec -it opencpu bash
Execute the command (if your odbc.ini section is other than DSN, replace it accordingly):
isql -v DSN
The output must be something like:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
An alternative to run each Docker image separatedly is executing:
docker-compose up -d
If the Docker image doesn't exist locally, it will be built automatically. If you prefer to download it from Docker Hub, run before:
docker pull savvydatainsights/opencpu-mysql