我正在尝试dockerize一个以前部署在windows上的应用程序,我想知道我应该使用什么python图像来解决安装pyodbc和pythonnet的问题。我的要求:
pyodbc = = 4.0.25pythonnet = =测试盒框
我得到的pyodbc错误状态:
src/pyodbc.h:56:10: fatal error: sql.h: no such file or directory
pythonnet错误:没有找到pythonnet的匹配发行版==2.4.0
我的Dockerfile是这样的:
FROM python:3.6
WORKDIR /opt
# create a virtual environment and add it to PATH so that it is applied for all subsequent run and cmd calls
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY requirements.txt
COPY src ./src
RUN pip install --no-cache-dir -r requirements.txt
cmd python src/automation/interface/app.py
我试着拉出一个windows-server-core映像,但得到一个错误消息说无法找到该映像,并且我无法找到任何其他正常运行的基于windows的映像。我需要解决这个问题,因为我的应用程序构建和导入一个c#应用程序,我需要pythonnet才能做到这一点。如有任何帮助,不胜感激。
这是一个你可以使用的Dockerfile
FROM python:3.6
WORKDIR /opt
# Install Mono for pythonnet.
RUN apt-get update
&& apt-get install --yes
apt-transport-https
dirmngr
clang
gnupg
ca-certificates
# Dependency for pyodbc.
unixodbc-dev
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
&& echo "deb http://download.mono-project.com/repo/debian stretch/snapshots/5.20 main" | tee /etc/apt/sources.list.d/mono-official-stable.list
&& apt-get update
&& apt-get install --yes
# https://github.com/pythonnet/pythonnet/issues/939#issuecomment-520904067
# https://github.com/jonemo/pythonnet-docker/blob/master/_dockerfiles/python3.6.10-mono5.20-pythonnet2.5.0
mono-devel=5.20*
&& rm -rf /var/lib/apt/lists/*
# create a virtual environment and add it to PATH so that it is applied for all subsequent run and cmd calls
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3 -m venv $VIRTUAL_ENV
# From here on, use virtual env's python.
&& python -m pip install --no-cache-dir --upgrade pip setuptools wheel
# Dependency for pythonnet.
&& python -m pip install --no-cache-dir pycparser
&& python -m pip install --no-cache-dir "pyodbc==4.0.25" "pythonnet==2.4.0"
这个Dockerfile安装Mono运行时,这似乎是linux上pythonnet所必需的。它还通过安装unixodbc-dev
来解决丢失的sql.h
文件(参见mkleehammer/pyodbc#441)。