Reputation: 429
I'm having some trouble getting Gitlab CI set up to build a docker image and push it to the Gitlab registry. I am attempting to use a shared runner provided by Gitlab. From what I've read, this should be possible, however, no matter what I try, as soon as the build reaches any 'docker' command it fails, with this message:
$ docker build --pull -t $CONTAINER_TEST_IMAGE .
/bin/bash: line 54: docker: command not found
I am using the following CI configuration:
image: "ruby:2.3"
services:
- docker:dind
- postgres:latest
variables:
POSTGRES_DB: test-db
CONTAINER_TEST_IMAGE: registry.gitlab.com/pha3l/gitlab-ci-test-project:$CI_BUILD_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/pha3l/gitlab-ci-test-project:latest
cache:
paths:
- vendor/ruby
stages:
- build
- test
- release
- deploy
before_script:
- ruby -v
- gem install bundler --no-ri --no-rdoc
- bundle install -j $(nproc) --path vendor
rubocop:
script:
- rubocop
rails:
variables:
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
script:
- bundle exec rake db:migrate
- bundle exec rake db:seed
- bundle exec rake test
build:
stage: build
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
release-image:
stage: release
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy:
stage: deploy
script:
- echo 'Do the deploy!'
only:
- master
Upvotes: 2
Views: 1769
Reputation: 1341
seems like these lines
services:
- docker:dind
Do not add docker binary to your image, only allow you to running docker in docker. You may have to create your own image based on ruby:2.3 and add docker utility explicitly. Dockerfile should look like this:
FROM ruby:2.3
MAINTAINER maintaner
# install docker
RUN apt-get update && \
apt-get install -y apt-transport-https ca-certificates gnupg2
RUN apt-key adv \
--keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main" | tee /etc/apt/sources.list.d/docker.list
RUN apt-get update && \
apt-get install -y docker-engine
Upvotes: 1