I am running a yml script in gitlab where I am using gitlab-ci.yaml to create a docker image and push it to Google Registry. Where as I am unable to run the commands. Here is my gitlab code.
image: docker:latest
services:
- docker:dind
variables:
SPRING_PROFILES_ACTIVE: gitlab-ci
stages:
- build
- imagecreation
- deploy
maven-build:
image: maven:3-jdk-8
stage: build
script: "mvn package -B"
artifacts:
paths:
- target/*.war
docker-build:
image: google/cloud-sdk
stage: imagecreation
script:
- docker build -t gcr.io/project-test-to/counter .
- gcloud docker -- push gcr.io/project-test-to/counter
k8s-deploy:
image: google/cloud-sdk
stage: deploy
script:
- echo "$GOOGLE_KEY" > key.json
- gcloud auth activate-service-account --key-file key.json
- gcloud config unset container/use_client_certificate
- gcloud container clusters get-credentials gitlab --zone us-central1-a --project project-test-to
- kubectl apply -f deployment.yaml
Her is the error that I am getting.Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ERROR: Job failed: exit code 1
How can I run the docker commands in this image?(google/cloud-sdk)
If this is CircleCI you are using to build the image you can use setup_remote_docker
as described in:
Then the config.yml
looks something like:
create_app_docker:
docker:
- image: google/cloud-sdk:latest
steps:
- checkout
- setup_remote_docker
- run:
name: Build docker with application
command: |
docker --version
docker build -t my-app ./
docker images
Following up on the original answer, the "gcloud docker" command is now deprecated as mentioned. To push an image to Container Registry, you just need to run the following:
$docker push
I would also suggest setting up the docker command so that you can run it as non root by following the steps mentioned in this documentation.
Since the gcloud docker
command simply passes commands to docker, and the docker image google/cloud-sdk
doesn't seem to ship with docker installed, you might need to mount your host socket into the container like this:
docker-build: image: google/cloud-sdk stage: imagecreation script: - docker build -t gcr.io/project-test-to/counter . - gcloud docker -- push gcr.io/project-test-to/counter volume: - "/var/run/docker.sock:/var/run/docker.sock"
Please also keep in mind the command gcloud docker
is deprecated.