I am trying to create a compose docker consisting of, shiny and plumber which refer to a single postgresql.
My docker-compose.yml is as follows:
version: "3" services: db: container_name: dartsviz_db image: kartoza/postgis:15-3.3 ports: - "5432:5432" volumes: - ./postgres_container/dumpfile:/var/lib/postgresql environment: - POSTGRES_DB=dartsviz-db - POSTGRES_USER=postgres - POSTGRES_PASS=postgres - POSTGRES_MULTIPLE_EXTENSIONS=postgis,postgis_raster plumber: container_name: plumber_api build: ./r_container ports: - "8787:8787" depends_on: - db shiny: container_name: shiny build: ./app_container depends_on: - db ports: - "80:80"
when I try to make the connection from the shiny app and plumber with the following code
remote_conn <- dbConnect(RPostgres::Postgres(), dbname = "dartsviz_db", host="db", port=5432, user="postgres", password="postgres")
returns me the following error
shiny | Warning: Error in : could not translate host name "postgres" to address: No address associated with hostname shiny | shiny | 46: <Anonymous> shiny | 45: stop shiny | 44: connection_create shiny | 43: .local shiny | 42: dbConnect shiny | 40: server shiny | 3: runApp shiny | 2: print.shiny.appobj shiny | 1: <Anonymous> shiny | Error : could not translate host name "postgres" to address: No address associated with hostname
What should I change to make it work?