2
votes

dockerfile:

FROM node:10
ADD . /app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "node", "index.js" ]

cloudbuild.yaml:

steps:
- name: buildcontainer
args: ['build', '-t', 'gcr.io/$PROJECT_ID/coffee2goserver:${SHORT_SHA}', '.']
- name: 'pushcontainer'
args: ["push", "gcr.io/$PROJECT_ID/coffee2goserver"]

error:

Error response from daemon: pull access denied for buildcontainer, repository does not exist or may require 'docker login'

1
I don't see any issue with the Dockerfile. Instead, try to add a step to docker login prior to calling the docker build - Anuradha Fernando
You're building and pushing different names; the push command needs to include the ${SHORT_SHA}. - David Maze

1 Answers

3
votes

Google Cloud Build doesn't provide any buildcontainer or pushcontainer images you can use in your builds (unless you have created them yourself).

You may use the official Docker image in your step like so:

steps:
- name: docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/coffee2goserver:${SHORT_SHA}', '.']
- name: docker
args: ["push", "gcr.io/$PROJECT_ID/coffee2goserver:${SHORT_SHA}"]

The Docker build step is automatically set up with credentials for your Cloud Build Service Account. These permissions are sufficient to interact directly with GCR.

Also, as David Maze@ mentioned in his comment, be careful to push your image with the same name it was build with, including the ${SHORT_SHA} in this case.