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??
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With