2

我在我的代码中使用 Cloudera Hive ODBC 驱动程序,并且我正在尝试将应用程序容器化。下面是我的 Dockerfile,

FROM ubuntu:18.04
FROM continuumio/anaconda3
FROM node:10
 

RUN conda update -n base -c defaults conda

RUN conda create -n env python=3.7
RUN echo "conda activate env" > ~/.bashrc
ENV PATH /opt/conda/envs/env/bin:$PATH
RUN apt-get update && apt-get install -y \
      curl apt-utils apt-transport-https debconf-utils gcc build-essential \
      && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
      python-pip python-dev python-setuptools \
      --no-install-recommends \
      && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip
RUN pip install pyyaml pandas numpy pymysql sqlalchemy schedule tornado
RUN apt-get update && apt-get install -y --no-install-recommends git unzip unixodbc unixodbc-dev
RUN conda install -c conda-forge turbodbc=3.1.1
RUN apt-get update && apt-get install -y gettext nano vim -y
RUN yarn install --modules-folder ./static
WORKDIR /app
COPY entry.sh /usr/local/bin/
COPY . /app/
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
      && apt-get install -y --no-install-recommends dialog \
      && apt-get update \
      && apt-get install -y --no-install-recommends openssh-server \
      && echo "$SSH_PASSWD" | chpasswd 
COPY sshd_config /etc/ssh/
COPY entry.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/entry.sh
EXPOSE 5000 2222 22 80 8000
CMD ["entry.sh"]

构建映像正在成功,但是当我运行 docker 映像时,我看到以下错误

Traceback (most recent call last):


File "app.py", line 14, in <module>
    from abc_scheduler import scheduler_main
  File "/app/abc_scheduler.py", line 5, in <module>
    from methods import Methods
  File "/app/methods.py", line 10, in <module>
    from utils import *
  File "/app/utils.py", line 2, in <module>
    from turbodbc import connect, make_options
ModuleNotFoundError: No module named 'turbodbc'

我在我的内部尝试了许多其他 ODBC Dockerfile,但没有运气。任何帮助都会很棒。

4

1 回答 1

0

正如@DavidMaze 所建议的,我成功创建了一个Dockerfile&如下所示

FROM ubuntu:latest
FROM continuumio/anaconda3
FROM node:10

RUN conda update -n base -c defaults conda

RUN conda create -n env python=3.7
RUN echo 'conda init bash' >/.bashrc
RUN echo "conda activate env" > ~/.bashrc

ENV PATH /opt/conda/envs/env/bin:$PATH
RUN apt-get update && apt-get install -y \
      curl apt-utils apt-transport-https debconf-utils gcc build-essential \
      && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
      python-pip python-dev python-setuptools \
      --no-install-recommends \
      && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip
# ==================TURBODBC========================
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y

RUN apt-get install -y alien # optional
COPY ClouderaHiveODBC-2.6.1.1001-1.x86_64.rpm /opt/cloudera/
RUN alien /opt/cloudera/ClouderaHiveODBC-2.6.1.1001-1.x86_64.rpm
RUN dpkg -i clouderahiveodbc_2.6.1.1001-2_amd64.deb
# ==================END=============================
RUN conda install --name env -c conda-forge turbodbc=4.1.1 tornado=6.0.4 pyyaml pymysql schedule sqlalchemy pyarrow numpy=1.19.3\
    pandas=1.1.4  pybind11 pyarrow
COPY odbc.ini /etc/
RUN apt-get update && apt-get install -y gettext nano vim -y
RUN yarn install --modules-folder ./static
WORKDIR /app
COPY . /app/
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
      && apt-get install -y --no-install-recommends dialog \
      && apt-get update \
      && apt-get install -y --no-install-recommends openssh-server \
      && echo "$SSH_PASSWD" | chpasswd 
COPY sshd_config /etc/ssh/
COPY entry.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/entry.sh
EXPOSE 9988 2222 22 80 8000
CMD ["entry.sh"]

在当前目录中保留一份副本ClouderaHiveODBC-2.6.1.1001-1.x86_64.rpm同时保留以下文件:

odbc.ini- 有数据库信息

entry.sh- 这是shell脚本并有一个命令 -python app.py

ssh_config- 没有任何扩展名的文件具有如下所示的信息

Port                    2222
ListenAddress           0.0.0.0
LoginGraceTime          180
X11Forwarding           yes
Ciphers                 aes128-cbc,3des-cbc,aes256-cbc
MACs                    hmac-sha1,hmac-sha1-96
StrictModes             yes
SyslogFacility          DAEMON
PrintMotd               no
IgnoreRhosts            no
#deprecated option
#RhostsAuthentication   no
RhostsRSAAuthentication yes
RSAAuthentication       no
PasswordAuthentication  yes
PermitEmptyPasswords    no
PermitRootLogin         yes
于 2020-12-11T04:38:12.550 回答