Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apt not found when I use apt in gitlab ci before_script

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??

like image 400
fuzes Avatar asked Mar 05 '19 06:03

fuzes


People also ask

What is Before_script in GitLab CI?

These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.

Does GitLab CI use Docker?

GitLab CI in conjunction with GitLab Runner can use Docker Engine to test and build any application. Docker is an open-source project that allows you to use predefined images to run applications in independent "containers" that are run within a single Linux instance.

What is Docker DIND in GitLab?

The docker:dind image is required because it actually starts up the docker daemon when it is brought up by a runner. The docker cli can exist on a host/container without having the daemon running and can be pointed to control a daemon running somewhere else.


3 Answers

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

like image 60
Prabhat Singh Avatar answered Oct 20 '22 21:10

Prabhat Singh


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

like image 8
jkrol2 Avatar answered Oct 20 '22 19:10

jkrol2


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

like image 5
Shrikant Mudholkar Avatar answered Oct 20 '22 19:10

Shrikant Mudholkar