0

I have a docker application set up, and install some R packages using the line:

RUN Rscript requirements.R, using the line install.packages('odbc)

I recently get an error when trying running a previously working application:

Error in library(odbc) : there is no package called ‘odbc’

reading through the build files, I noticed different language used while installing:

when it worked: installing *binary* package ‘odbc’

when it failed: installing *source* package ‘odbc’ , and I am getting the error fatal error: sql.h: No such file or directory

Is there a way to force the correct call? or a way to correct the error received concerning the sql-h. I tried including RUN sudo apt-get install unixodbc unixodbc-dev as per sql.h not found when installing PyODBC on Heroku and RUN sudo apt install unixodbc-dev as per https://github.com/mkleehammer/pyodbc/issues/441

edit:

I just ran this pipeline in Azure, and the files show installing *binary* package ‘odbc’ and it successfully compiled My Dockerfile:

FROM rocker/verse
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev python3.9 python3-pip python3-setuptools python3-dev
RUN pip3 install --upgrade pip
RUN apt -y install libpng-dev
WORKDIR /app
RUN apt-get install --yes xvfb libgconf-2-4
RUN wget https://github.com/plotly/orca/releases/download/v1.1.1/orca-1.1.1-x86_64.AppImage -P /home
RUN chmod 777 /home/orca-1.1.1-x86_64.AppImage
ENV PATH="${PATH}:/home/orca-1.1.1-x86_64.AppImage"
RUN cd /home && /home/orca-1.1.1-x86_64.AppImage --appimage-extract
RUN printf '#!/bin/bash \nxvfb-run --auto-servernum --server-args "-screen 0 640x480x24" /home/squashfs-root/app/orca "$@"' > /usr/bin/orca
RUN chmod 777 /usr/bin/orca
RUN chmod -R 777 /home/squashfs-root/
RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` &&     mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION &&     curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip &&     unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION &&     rm /tmp/chromedriver_linux64.zip &&     chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver &&     ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver
RUN apt-get update && apt-get install -y gnupg2
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -     && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable
RUN wget https://downloads.vivaldi.com/stable/vivaldi-stable_5.5.2805.35-1_amd64.deb
RUN apt-get update && apt-get install -y ./vivaldi-stable_5.5.2805.35-1_amd64.deb && rm -rf /var/lib/apt/lists/*

# Install odbc
RUN sudo su
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN exit
RUN sudo apt-get clean
RUN sudo apt-get update && apt install -y apt-utils
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN sudo apt-get remove -y libodbc2 libodbcinst2 odbcinst unixodbc-common
RUN sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17

# set up app
COPY . /app
RUN pip3 install -r requirements.txt
RUN Rscript requirements.R

## Start and enable SSH
COPY sshd_config /etc/ssh/

RUN apt-get update \
    && apt-get install -y --no-install-recommends dialog \
    && apt-get install -y --no-install-recommends openssh-server \
    && echo "root:Docker!" | chpasswd \
    && chmod u+x /app/entrypoint.sh

EXPOSE 8501 2222
RUN chmod -R 777 /app
WORKDIR /app
RUN ls .
RUN service ssh start
CMD ["/bin/bash", "-c", "service ssh start; streamlit run app.py"]
frank
  • 3,036
  • 7
  • 33
  • 65
  • Please share your `Dockerfile`. There's no way to "force" compilation of R's `odbc` package if the underlying OS-level packages (as you list at the end of your question) are not found. The binary package may not need `sql.h`, but it still needs the underlying shared libraries (e.g., `libodbc.so.2`). Perhaps there's something in your dockerfile (order of operations, incomplete, failed, etc) where the fix should be focused. If `apt-get install unixodbc unixodbc-dev` is done before R, and then R's `install.packages("odbc")` is done correctly, the only remaining hurdle is `.libPaths()`. – r2evans Apr 24 '23 at 12:09
  • @r2evans my dockerfile included above. It compiled successfully this time, but it would be good to know why it used the `binary` and not the `source` reference – frank Apr 24 '23 at 13:02
  • 1
    There is a lot of redundancy in this dockerfile. I'm nearly _certain_ that `apt-get update` is not going to change between each step, so you should do it only once (and move `apt-get clean` to after your last `apt-get install`); that will both reduce the build time and reduce the load on upstream servers. I'm confused that you intend to use ODBC but you explicitly _remove it_ with `apt-get remove -y libodbc2 ...` (if you run `ldd .../R/x86_64-pc-linux-gnu-library/4.2/odbc/libs/odbc.so` (wherever that lives in your image), you'll see that it uses `libodbc.so.2`.) – r2evans Apr 24 '23 at 13:14

0 Answers0