Pipeline CI build job with dind and default ruby:2.5 image

Apologies if I’ve misunderstood but what I’m trying to achieve is a CI build that contains Python 3 and pip 3 and then builds a docker image from my project’s python source and the installed packages.

The .gitlab-ci.yml doesn’t specify an image, so the default ruby:2.5 image is used.

build_image_job:
  stage: build
  script:
    - apt-get update -qy
    - apt-get install -y python3.7 python3.7-dev python3-pip
    - pip3 install -r requirements/prod.txt

    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker build -t $CONTAINER_TEST_IMAGE -f docker/Dockerfile .
    - docker push $CONTAINER_TEST_IMAGE

However of course the ruby:2.5 image doesn’t contain the Docker CLI.

I tried switching to docker:dind as the image, however that is based on Alpine and use apk not apt, and some of the package I’m using don’t play nice with apk and cause a lot of issues. apt-get however works fine on ruby:2.5

What’s the best way forward to be able to build a docker image from my gitlab job?

Hi,

we had a similar issue last week with using dind for building Elastic Beat packages. Turns out, the default dind alpine image is hard to tackle here. With using a different image, one needs to build the Docker wrapper logic/script.

This archived repo points to some of those parts, where you’ll likely don’t want to go by yourself.

Question: Why do you need Python to build a docker image? Can you provide a little more context of what you’re planning to do?

Cheers,
Michael

The image that we’re building with Docker contains Python Flask services. We also have some 3rd party and our own packages we need to install on that image. The docker image is then part of a large suite of containers deployed with docker-compose.

I’m not sure I can follow here. Can you please share the content of your Dockerfile? Imho the outside docker build process doesn’t need python at all, that’s done with instructing the Dockerfile to actually do that.