Images¶
Goal
Learn how to...
- specify which container image to use for a job
- tailor the execution environment to your needs
Task: Simplify using container images¶
In the previous exampes, we called apk
at the beginning of every job to install Go. This had to be repeated for every job because Go was not present. Choosing an image for a job using the image
directive, time is saved by avoiding commands to install required tools. See the official documentation.
Replace the calls to apk
with the container image golang:1.19.2
.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
Hint (Click if you are stuck)
- Remove
before_script
- Add
image: golang:1.19.2
instead
Solution (Click if you are stuck)
.gitlab-ci.yml
:
If you want to jump to the solution, execute the following command:
Bonus: Test different images¶
Add a job to your pipeline to test different container images. Check how different images offer specialized execution environments:
- Use
python:3
and test runningpython --version
- Use
node
and test runningnode --version