Reputation: 1469
I would like to build a Docker image when I push code to gitlab.com.
This works fine, up to a point...
gitlab-ci.yml (1)
image: php:7.4
cache:
paths:
- vendor/
before_script:
- echo "Prep me"
- apt-get update
- apt-get install -y --no-install-recommends zip unzip gnupg2
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
build:
script:
- echo "Build me"
- composer install
- yarn install
But nothing gets added into the Gitlab registry. So I've tried adding this to build but docker is not a recognized command.
gitlab-ci.yml (2)
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
I would have thought it should be simple to get a PHP docker image spun up in no time but it seems to be difficult - unless I'm missing something?
Upvotes: 1
Views: 2730
Reputation: 39119
The reason is that the base image of your GitLab CI right now is php:7.4
, which does not have the docker commands.
In order to achieve running docker command you will need to use an image like
image: docker:19.03.8
Upvotes: 1