PostgreSQL: accessing local and external database from container

I have some difficulties to connect my shiny app to a local and remote db with RPostreSQL.
Both databases are not runnning inside a container.

Summary of steps undertaken:

1. I first build the docker container with the dockerfile:

    FROM rocker/r-devel
    RUN apt-get update && apt-get install -y \
        sudo \
        build-essential \
        pandoc \
        pandoc-citeproc \
        curl \
        libxml2-dev \
        libcairo2-dev \
        libxt-dev \
        libssl-dev \
        libssh2-1-dev \
        libpcre3 \
        libpcre3-dev \
        libpq-dev

    RUN apt-get update && apt-get install -y \
        libmpfr-dev

    RUN R -e "install.packages(c(  \
        'tidyverse',  \
        'stats', \
        'methods', \
        'shinyWidgets', \
        'shiny', \
        'shinyBS', \
        'shinydashboard', \
        'shinyjs', \
        'readr', \
        'readxl', \
        'cellranger', \
        'attempt', \
        'dplyr', \
        'magrittr', \
        'pool', \
        'RPostgreSQL', \
        'stringr', \
        'purrr', \
        'glue', \
        'lubridate' \
    ), repos='https://cloud.r-project.org/')"

    RUN mkdir /root/mypackage
    COPY mypackage_0.1.0_R_x86_64-pc-linux-gnu.tar.gz /root/mypackage
    RUN R -e "install.packages('/root/mypackage/mypackage_0.1.0_R_x86_64-pc-linux-gnu.tar.gz', repos = NULL, type='source')"
    COPY Rprofile.site /usr/lib/R/etc/

    EXPOSE 3838

    CMD ["R", "-e", "mypackage::run_shiny_app()"]

2. Then the application.yml:

shiny:
  proxy:
    title: Shiny app with postgres connection
    landing-page: /
    heartbeat-rate: 10000
    heartbeat-timeout: 60000
    port: 8080
    container-wait-time: 60000	
    hide-navbar: true
    authentication: none
    docker:
      cert-path: /home/none
      url: http://localhost:2375
      port-range-start: 20000
  apps:
  - name: app
    display-name: app
    description: A shiny app
    docker-cmd: ["R", "-e", "mypackage::run_shiny_app()"]
    docker-image: mypackagecontainer
    docker-network: "host"
logging:
  file:
    shinyproxy.log

3. I start the shinyProxy server with:

      java -jar shinyproxy-1.0.2.jar 

It results in a 'ShinyProxyException: Container did not respond in time
If i remove docker-network: "host", the app runs normally without errors but i can’t have access to the local db.

when i do:

sudo docker run --net=host -it -p  3838:3838 mypackagecontainer

All is working correctly and i have access to the database.

Questions:

  1. How to avoid the error when i add docker-network: "host"?
  2. How to configure the application.yml to have access to the external db “xxxxx.x.fr:5432” for exemple ?

For accessing a local Postgres server that should listen only on local IPs I have used the technique described in https://web.archive.org/web/20160510024612/http://blog.jvc26.org/2016/01/22/host-postgresql-container-connections/.