Python symbol lookup error when running PyODBC and MySQL in a Docker container. What to do? - odbc

I am trying to connect to a MySQL database using PyODBC in a Docker container. When I run the script it gives the error python: symbol lookup error: /usr/local/lib/private/libssl.so.1.1: undefined symbol: EVP_idea_cbc, version OPENSSL_1_1_0.
This is my Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.10
WORKDIR /app
COPY requirements.txt requirements.txt
ARG PYPI_USERNAME
ARG PYPI_PASSWORD
# Install PyODBC requirements
RUN apt-get update && \
apt-get -y install g++ unixodbc-dev openssl
# Install MySQL ODBC driver
ADD https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz .
RUN tar -C . -xzvf mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz
RUN cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/bin/* /usr/local/bin
RUN cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/lib/* /usr/local/lib
RUN myodbc-installer -a -d -n "MySQL ODBC 8.0 Driver" -t "Driver=/usr/local/lib/libmyodbc8w.so"
RUN myodbc-installer -a -d -n "MySQL ODBC 8.0" -t "Driver=/usr/local/lib/libmyodbc8a.so"
# Run pip as a python module to access environment variables in requirements.txt
RUN python -m pip install --no-cache-dir -r requirements.txt
COPY . .
CMD python script.py
After some research it seems to me that the issue stems not from Python but from my libraries being messed up for some reason. I tried installing openssl using apt-get but to no avail. I am at a loss as to how to proceed as this is really not my forte. Any help would be greatly appreciated!

Related

Installing R in a docker container

I'm trying to install in a Ubuntu:20.04 based container miniconda and, using the conda keyword, R:4.05.
The Dockerfile I'm using is this:
FROM ubuntu:20.04
USER root
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev
RUN apt-get install -y wget
RUN mkdir -p ~/miniconda3
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
RUN bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
RUN export PATH=~/miniconda3/bin:$PATH
RUN rm -rf ~/miniconda3/miniconda.sh
RUN ~/miniconda3/bin/conda init bash
RUN ~/miniconda3/bin/conda init zsh
RUN ~/miniconda3/bin/conda config --add channels conda-forge
RUN ~/miniconda3/bin/activate
RUN ~/miniconda3/bin/conda install -y -c conda-forge r-base
RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('DESeq2')"
From lines 8 to 16 I download miniconda and run it in ~/miniconda3
In line 17:
RUN R -e "install.packages('BiocManager')"
I try to use R and install the BiocManager package from the command line, but I receive this error:
> [16/17] RUN R -e "install.packages('BiocManager')":
#19 2.767 /bin/sh: 1: R: not found
------
executor failed running [/bin/sh -c R -e "install.packages('BiocManager')"]: exit code: 127
I've also tried to start from the official distribution of Rocker, but in this way (the way I've shown you in this post) I would prefer it since I would end up with an image in which I have both miniconda and R.
Can someone help me?
Thanks a lot!
Each RUN command runs in a separate shell, so your export command sets the path, but then the shell exits and the path is reset for the next RUN command.
You also have to use the absolute path. Tilde expansion doesn't work.
Instead of
RUN export PATH=~/miniconda3/bin:$PATH
try
ENV PATH=/root/miniconda3/bin:$PATH

Why renv in docker is not installing and loading packages?

This is the first time I'm using Docker. I have tried a few times but this is the first time where I'm containerizing the project. The project generates reports using latex and officer. However, after building the container and running the image, Rstudio shows that none of the packages are installed and loaded.
Dockerfile
FROM rocker/verse:4.0.5
ENV RENV_VERSION 0.15.1
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv#${RENV_VERSION}')"
WORKDIR /REAL
COPY . .
RUN apt-get -y update --fix-missing
#RUN apt-get -y install build-essential \
# libssl-dev \
# libcurl4-openssl-dev \
# libxml2-dev \
# libfontconfig1-dev \
# libcairo2-dev
RUN R -e 'options(renv.consent = TRUE); renv::restore(lockfile = "/REAL/renv.lock"); renv::activate()'
Building Docker image
docker build -t reports/real .
Running docker with rstudio support
docker run --rm -d -p 8787:8787 --name real_report -e ROOT=TRUE -e DISABLE_AUTH=TRUE -v C:/Users/test/sources/REAL_Reports:/home/rstudio/REAL_Reports reports/real:latest
What am I doing wrong and how do I fix it so that all packages that renv has discovered are installed and loaded?
RUN R -e 'options(renv.consent = TRUE); renv::restore(lockfile = "/REAL/renv.lock"); renv::activate()'
You likely need to activate / load your project before calling restore(), or just forego using a project-local library altogether.
https://rstudio.github.io/renv/articles/docker.html may also be useful here.

Azure container - simple R plumber deployment question?

I am deploying simple plumber API in Azure container which executes simple SQL query and returns results. Here is my Dockerfile.
# start from the rocker/r-ver:4.0.2 image
# minor change to one branch to test deployment
FROM rocker/r-ver:4.0.2
# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev \
libsodium-dev \
unixodbc-dev \
r-cran-rodbc \
curl\
libxml2-dev
# libiodbc2-dev
# We need to update Dockerfile to install ODBC Driver 17 for SQL Server for
# Ubuntu 20.04 or different version
# here is link: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#ubuntu17
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
# RUN source /etc/bash.bashrc
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
# I probably do not even have to set up WORKDIR
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# install plumber
RUN R -e "install.packages('plumber')"
RUN R -e "install.packages('renv')"
RUN R -e "install.packages('RODBC')"
RUN R -e 'renv::restore()'
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
API works fine. However, when I connect to container, run R and execute library(RODBC) I get back error about library not found. This is puzzling since it is already mentioned in Dockerfile, but maybe it has something to do with renv. I proceed with installation install.packages('RODBC') and it generates error which I can fix by running apt-get install unixodbc-dev and apt-get install r-cran-rodbc. Those lines are again already present in Dockerfile. Then when I try to connect to SQL server I get error about driver. And again I can fix it by re-executing lines from Dockerfile (related to SQL Server 17 driver).
So I am puzzled why I need to re-execute some items already present in Dockerfile. Or maybe when I click "Connect" in Azure it actually connects me to host and not to container?

How to install a specific version of node in a Ubuntu environment

When I docker run -it wordpress:php7.0-apache I could execute all of those following command
FROM wordpress:php7.0-apache
RUN apt-get update
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
RUN /bin/dash ~/.profile
RUN /bin/dash nvm install 8.11.4
My issue is when I try to docker build -t imageName:version I would have an error :
/bin/dash: 0: Can't open nvm
The command '/bin/sh -c /bin/dash nvm install 8.11.4' returned a non-zero code: 1277
What could be the difference ?
Thank you David Maze. Indeed there is no need of nvm to install a specific version.
My Dockerfile now :
FROM wordpress:php7.0-apache
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs

centos AWS shiny server wont resolve

Set up using AWS instance running centOS 6.4 with R and shiny server using my Macbook and trying to figure out what is wrong with it as there are issues with this process
# set up AWS Redhat 6.4 instance (dont forget to download .pem)
# set the .pem file into your ~/.ssh/ folder and make sure you chmod the file
chmod 400 ~/.ssh/myshinypemexample.pem
ssh into machine
ssh -i ~/.ssh/myshinypemexample.pem root#yourPublicDNS
# the first time you run this, just press yes, don't be scared :)
# use ec2-user and log into machine
ssh -i ~/.ssh/myshinypemexample.pem ec2-user#yourPublicDNS
Get the EPEL rpm
wget http://mirror.us.leaseweb.net/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm --test
Import the EPEL GPG key
wget https://www.fedoraproject.org/static/0608B895.txt
sudo mv 0608B895.txt /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Verify that the key has been imported.
rpm -qa gpg*
## You should see a line like this: gpg-pubkey-0608b895-4bd22942
Install the rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm
Install shiny server
sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
# this gives error and have to install Rcpp and httr manually
wget http://cran.r-project.org/src/contrib/Rcpp_0.11.1.tar.gz
sudo R CMD INSTALL --build Rcpp_0.11.1.tar.gz
wget http://cran.r-project.org/src/contrib/httpuv_1.2.3.tar.gz
sudo R CMD INSTALL --build httpuv_1.2.3.tar.gz
run shiny server again
sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
Install Shiny Server
wget http://download3.rstudio.org/centos-5.9/x86_64/shiny-server-1.0.0.42-x86_64.rpm
sudo yum install --nogpgcheck shiny-server-1.0.0.42-x86_64.rpm
# test server
sudo status shiny-server
check location of example shiny app
sudo R -e "system.file('examples/01_hello', package='shiny')"
[1] "/usr/lib64/R/library/shiny/examples/01_hello"
#copy example file from R to /srv as Shiny looks for this location to work
sudo cp -R /usr/lib64/R/library/shiny/examples/01_hello /srv/shiny-server/
MYIP:3838 does not resolve. Why?

Resources