18

我使用 gitlab ci 构建 docker 映像,我想安装 python。当我构建时,以下是我的 gitlab-ci.yml:

image: docker:stable
stages:
  - test
  - build

before-script:
  - apt install -y python-dev python pip

test1:
  stage: test
  script:
  ...
    - pytest

build:
  stage: build
  - docker build -t $IMAGE_TAG .
  - docker push $IMAGE_TAG

但我的工作失败了

/bin/sh: eval: line : apt: not found
ERROR: Job failed: exit code 127

我也尝试过 apt-get install 但结果是一样的。

我如何安装python?

4

3 回答 3

17

这实际上不是问题,但您可以说它是由 Alpine 的包管理器提供的,您正在使用 image: docker:stable 或任何此类图像,例如它们在 Alpine Linux 上的 tomcat 或 Django。尺寸最小。

image: docker:stable
stages:
 - test
 - build

before-script:
 - apk add python python-dev python pip

test1:
stage: test
script:
...
- pytest

build:
stage: build
 - docker build -t $IMAGE_TAG .
 - docker push $IMAGE_TAG

apk 是 Alpine Linux 包管理

于 2019-03-05T07:24:45.793 回答
8

您正在使用 docker: stable 的映像基于Alpine Linux,它apk用作其包管理器。安装apk将如下所示:apk add python

于 2019-03-05T06:54:40.960 回答
5

您看到的错误是因为 apt 在 alpine docker 中不存在。

这条线为我解决了这个问题:

apk update && apk add python

于 2019-12-06T16:18:17.540 回答