I created an instance of RStudio running inside of a docker container. When working inside of the container, I get the following error when trying to connect to Postgres database: "Error: could not translate host name "ABC-123" to address: Name or service not known".
On my local machine, I execute this step very easily like this:
# Load Libraries
# renv::init()
library(tidyverse)
library(glue)
library(dbplyr)
library(odbc)
library(DBI)
library(RPostgreSQL)
library(sendmailR)
library(paws)
library(config)
library(fs)
# renv::snapshot()
con <- dbConnect(RPostgres::Postgres(),
dbname = EDP_db,
host = EDP_host_db,
port = EDP_db_port,
user = EDP_db_user,
password = EDP_db_password)
However, inside of the container I get the above mentioned error.
Here is the code for my dockerfile:
FROM rocker/tidyverse:latest
# environment variables
ENV RENV_CONFIG_REPOS_OVERRIDE https://packagemanager.rstudio.com/cran/latest
# Install dependency libraries
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
build-essential \
libxml2-dev \
libcurl4-openssl-dev \
libicu-dev \
libsodium-dev \
libssl-dev \
libmagick++-dev \
libudunits2-dev \
libgdal-dev \
libgeos-dev \
libproj-dev \
lbzip2 \
libpq-dev \
make \
&& apt-get clean
# expose port on Docker container (Ports that docker opens up) & set working directory
EXPOSE 8787
EXPOSE 5610 # (Port of DB)
EXPOSE 1440
RUN mkdir -p /app
RUN chmod -R 755 /app
WORKDIR /app/
# install R-packages into Docker container
COPY renv.lock renv.lock
RUN Rscript -e "install.packages('renv', repos = 'http://cran.us.r-project.org')"
RUN Rscript -e "renv::restore()"
# copy necessary files and data into app folder
COPY daily_leads.R /app/daily_leads.R
COPY config.yml /app/config.yml
COPY qk526-rpms-rp-daily-leads.Rproj /app/qk526-rpms-rp-daily-leads-app.Rproj
Lastly, here is the commands that I am using to build the docker image:
docker build -t daily_leads_app:1.0 --build-arg HTTP_PROXY="http://LCPzen.fpl.com:10262" --build-arg HTTPS_PROXY="http://LCPzen.fpl.com:10262" .
docker run --rm -d -p 8787:8787 daily_leads_app:1.0
This is a project for my job, hence the reason for the proxy. I am not sure what type of network that the docker host is configured to use, nor how to configure said network. I have been doing my best to google possible solutions, and the suggestions that seem to be most applicable recommend using a docker compose yaml file to initiate an instance of a postgres database and then make sure the name of the host is the name of the database service you've chosen in docker-compose.yml. However, the database that I am connecting to is a private company database, not something that I can save to my local machine. (Oh, and the error message mentioned above is the copy and pasted error message recieved in the Rstudio console.)