我正在尝试通过在 docker 容器内使用 docker-compose 来运行 shell 脚本。我正在使用 Dockerfile 构建容器环境并安装所有依赖项。然后我将所有项目文件复制到容器中。据我所知,这很有效。(我对 docker、docker-compose 还是比较陌生的)
我的 Dockerfile:
FROM python:3.6-alpine3.7
RUN apk add --no-cache --update \
python3 python3-dev gcc \
gfortran musl-dev \
libffi-dev openssl-dev
RUN pip install --upgrade pip
ENV PYTHONUNBUFFERED 1
ENV APP /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir $APP
WORKDIR $APP
ADD requirements.txt .
RUN pip install -r requirements.txt
COPY . .
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试的是:
docker-compose 文件:
version: "2"
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 docker 容器中安装一个 numpy 依赖项。(我的代码大量使用它)。在构建容器时,numpy 库根本不会安装并且构建失败。这是在操作系统 raspbian-buster/stretch 上。然而,这在 MAC OS 上构建容器时确实有效。
我怀疑某种与 python 相关的问题,但我一生都无法弄清楚如何使它工作。
我应该指出,从需求文件中删除 pip install numpy 并在 dockerfile 中它自己的 RUN 语句中使用它并不能解决问题。
Dockerfile:
FROM python:3.6
ENV PYTHONUNBUFFERED 1
ENV APP /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir $APP
WORKDIR $APP
ADD requirements.txt .
RUN pip install -r requirements.txt
COPY . .
Run Code Online (Sandbox Code Playgroud)
requirements.txt 包含所有项目需求,即 numpy 的 amounf。
Step 6/15 : RUN pip install numpy==1.14.3
---> Running in 266a2132b078
Collecting numpy==1.14.3
Downloading https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/numpy-1.14.3.zip (4.9MB)
Building …Run Code Online (Sandbox Code Playgroud)