首页 > 解决方案 > 如何概括用于 Docker 图像的 python?

问题描述

抱歉,如果这是一个不好的问题,我仍然是 Docker 的初学者,所以我寻求您的理解。

我正在尝试对应用程序进行 dockerize 处理。在应用程序中,有一个 json 配置文件,其中说明了 python 的文件路径。它用于不同的机器有不同的 python 路径。

例如,

{ "python_file_path":"/home/ubuntu/miniconda3/bin/python", "other_config":"exampleconfig" }.

此配置文件最初位于我试图 dockerize 的项目文件夹中。

但是,在对应用程序进行 dockerizing 并尝试在另一台机器上运行我的图像后,出现以下错误:

FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/miniconda3/bin/python': '/home/ubuntu/miniconda3/bin/python'

因此,我想知道 Docker 是如何在构建映像时准确打包所需的 python 的?另外,如何更改 json 文件以使其在所有机器上通用?

这是我的码头文件。我的运行命令是docker run -p 4000:80 nlpengine

# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /transfer_learning

# Copy the current directory contents into the container at /app
COPY . /transfer_learning

# Install any needed packages specified in requirements.txt
RUN apt-get update
RUN apt-get -y install gcc mono-mcs
RUN apt-get -y install unixodbc unixodbc-dev
RUN apt-get -y install --reinstall build-essential
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN python -m spacy download en

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "nlp_engine_daemon.py"]

标签: pythondocker

解决方案


推荐阅读