23

I use gitlab ci to build docker image and I want to install python. When I build, the following is my 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

but i got a Job failed

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

I also tried to apt-get install but the result is the same.

How do I install python??

fuzes
  • 1,777
  • 4
  • 20
  • 40

3 Answers3

24

It's actually not a problem but you can say it featured by package-manager with Alpine you are using image: docker:stable or any such images like tomcat or Django they are on Alpine Linux. with minimal in the size .

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 is Alpine Linux package management

Prabhat Singh
  • 891
  • 8
  • 17
10

The image that you are using docker: stable is based on Alpine Linux which uses apk as its package manager. installation with apk will look like that: apk add python

mr_incredible
  • 837
  • 2
  • 8
  • 21
jkrol2
  • 394
  • 1
  • 6
8

The error you see is because apt doesn’t exist in alpine docker.

This line solved the problem for me:

apk update && apk add python

Igor Escodro
  • 1,307
  • 2
  • 16
  • 30