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 (v. 2.5.0). 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

I have set in application.yml container-network to host so that my R application should connect to MySQL server using 127.0.0.0 (or localhost, I have tried both).

The Rprofile.site file contains

local({
   options(shiny.port = 3838, shiny.host = "0.0.0.0")
})

docker-network: host should be specified in the section of application.yml related to the application since each application is a different container.
Otherwise, if you use the default bridge networking, then replace 127.0.0.1 with the IP address of the MySQL server.

1 Like

I had already written docker-network: host in the specific application section of application.yml file. I also tried to replace 127.0.0.1 in app.R with the IP address of the host machine (it’s the same machine hosting MySQL, Docker and ShinyProxy), but the result is the same. I report the structure of the application.yml file I use.

proxy:
  title: TITLE
  logo-url: http://example.com/logo.png
  landing-page: /
  heartbeat-rate: 15000
  heartbeat-timeout: 900000
  port: 8080
  template-path: ./html
  authentication: simple
  admin-groups: [group1, group2]
  container-wait-time: 20000
  users:
  - name: user1
    password: ****************
    groups: group1
  - name: user2
    password: ****************
    groups: group2
  docker:
    cert-path: /home/none
    url: http://localhost:2375
    port-range-start: 20000
    container-protocol: http
  specs:
  - id: APP_1
    display-name: App1
    description: App1
    container-image: docker_image_name
    docker-network: host
    access-groups: [group1, group2]

spring:
  servlet:
    multipart:
      max-file-size: 300MB
      max-request-size: 300MB