shinyproxy
shinyproxy copied to clipboard
Connecting Shiny app to MySQL database running on host gives "Container did not respond in time"
I have a MySQL database running on Ubuntu and I try to connect to it from a Shiny app running in Shinyproxy. However, I cannot get it to work. Whenever I try to connect to the database I get the 500 Error (Container did not respond in time). The lines that create the error are:
stuffDB <- dbPool( RMySQL::MySQL(), user = "USERNAME", password = "PASSWORD", dbname = "DB_NAME", host = "127.0.0.1", port=3306 )
All the necessary libraries are installed and when I run the application from the container as
sudo docker run -it -p 3838:3838 --network="host" my_docker_image R -e "shiny::runApp('MyApp')"
it works fine. I set docker-network: host in application.yml to access the host MySQL database. I also tried specifying the socket as container-volumes: ["/var/lib/mysql/mysql.sock:/mysql.sock"] and tried adding the following lines to MySQL my.conf file: [client] protocol=tcp
The Rprofile.site file contains local({ options(shiny.port = 3838, shiny.host = "0.0.0.0") })
Hi @grazioli which version of shinyproxy are you running?
Have you tried setting container-network in the app definition in your application.yml ?
Hi @dseynaev, I'm using ShinyProxy v. 2.5.0 and I have set container-network to host so that my R application can connect to MySQL server using 127.0.0.0 (or localhost, I have tried both).
@dseynaev if you need any other info about my configuration please let me know. Thanks.
Hi, running apps when container-network is to host will never work and is unsupported by ShinyProxy.
You should remove that option. Next, you can re-configure the database to run on the network of the docker network. For example, if your docker network is 172.17.0.0/16, you should have your database listen on 172.17.0.1. If you cannot re-configure your database, you can use iptables to map the port using NAT. See e.g. https://serverfault.com/questions/586486/how-to-do-the-port-forwarding-from-one-ip-to-another-ip-in-same-network