繁体   English   中英

我如何在 docker 容器中只设置 python 2.7?

[英]how do i setup only python 2.7 in docker container?

我有节点应用程序,在一个用例中,我使用python-shell从节点调用 python 脚本。 我正在尝试在 docker 上设置这个应用程序,我的 Dockerfile 看起来像这样

FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean
# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.15.3
# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash
# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# confirm installation
RUN node -v
RUN npm -v
RUN apt-get -y install python2.7
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","run","start"]

在构建并运行此容器后,当我尝试调用从节点调用 python 脚本的用例时,我收到此错误。

null
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn /usr/lib/python2.7 EACCES
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

您可以使用 python 基础图像

FROM python:2.7

这个基础镜像已经预先配置了 python,你不需要单独安装 python。 希望能帮助到你。

这是可用图像的列表

如需快速参考,请查看https://blog.realkinetic.com/building-minimal-docker-containers-for-python-applications-37d0272c52f3

您可以使用 "FROM python:2.7" 基础映像。

 FROM python:2.7 WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD [ "python", "./your-daemon-or-script.py" ]

(文档链接)请在此处找到一些示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM