apt not found when I use apt in gitlab ci before_script

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


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


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