tensorflow Docker公司没有apt?

2024-05-19 03:40:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要使用tensorflow的遗留版本来编译一个项目。为此,我们设置了docker compose文件:

version: "3.8"

services:
  exercise:
    build:
      context: .
    container_name: practical_4
    environment:
      DATASET: cifar
    volumes:
      - "./:/app/"

    command: bash run.sh

我的Dockerfile看起来是这样的:

FROM tensorflow/tensorflow:1.15.2

WORKDIR /app
COPY . /app/

RUN ['apt', 'install', 'python-pip']
#RUN ['pip', 'install', 'matplotlib']

最后是运行脚本:

#!/bin/bash

echo "$DATASET"

# Install dependencies
pip install matplotlib
pip install numpy
pip install pickle

if [ $DATASET = "cifar" ]; then
  python cifar_cnn.py
else
  python mnist_cnn.py
fi

现在,当运行docker-compose up时,该过程失败。对于某些情况,找不到命令apt

Step 4/5 : RUN ['apt', 'install', 'python-pip']
 ---> Running in 39c9c48240b5
/bin/sh: 1: [apt,: not found
ERROR: Service 'exercise' failed to build: The command '/bin/sh -c ['apt', 'install', 'python-pip']' returned a non-zero code: 127

为什么会这样?我该如何解决这个问题


Tags: installpipcomposedockerrunbuildappbin
2条回答

docs

The exec form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).

因此,如果要使用exec表单,请尝试:

RUN ["apt", "install", "python-pip"]

还有shell形式:

RUN apt install python-pip

这种形式更适合您的情况,因为当您希望在不同的(而不是/bin/sh -c)shell中运行命令时,通常使用exec形式,例如:

RUN ["/bin/bash", "-c", "apt install python-pip"]

尝试:

RUN apt-get upgrade && apt-get install -y python-pip

相关问题 更多 >

    热门问题