5

I'm following this tutorial: https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app for Google Cloud Platform. I'm using the Google Cloud Shell command line. When I got to the step: To build the container image of this application and tag it for uploading, run the following command:

docker build -t gcr.io/${PROJECT_ID}/hello-app:v1 .

I get an error:

invalid argument "gcr.io//hello-app:v1" for "-t, --tag" flag: invalid reference format

Bear in mind I already have 3 instances cluster (created from Kubernetes Engine) and one VM instance created on its own, existing in my VM instances, created from previous tutorials. Not sure if this has anything to do with the error. Thanks in advance.

4 Answers 4

8

You missed setting PROJECT_ID. In the the "Before you begin" section of the tutorial you linked to it has you run

gcloud config set project [PROJECT_ID]

and then in Step 1 you run

export PROJECT_ID="$(gcloud config get-value project -q)"

After those two commands you should have the shell variable set correctly.

6
  • Thanks Robert. Indeed I missed that step. Silly error. After re-doing all the steps again, I got a different error at the same step - of building the container image: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/hazzaldo2/Dockerfi le: no such file or directory
    – Hazzaldo
    Jun 26, 2019 at 0:25
  • Strange. I just created a brand new cloud shell in a fresh project and the steps all worked fine for me. The only thing that looks weird is the space in Dockerfi le (unless that was a line break that pasted strangely). If you run ls /home/hazzaldo2/Dockerfile what does that return? Jun 26, 2019 at 6:13
  • Thanks for the response Robert. When I run ls /home/hazzaldo2/Dockerfile I get: ls: cannot access '/home/hazzaldo2/Dockerfile': No such file or directory. If I run ls on its own I get: README-cloudshell.txt. I'm not sure is it looking for the current directory inside my project in GCP, or is it looking else where? If so how to access the directory tree inside my project in GCP?
    – Hazzaldo
    Jun 26, 2019 at 10:55
  • 1
    After you git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples make sure you cd into the directory that is created, which will contain a Dockerfile. That is the file that you will use to create the image. If you are running the docker build from your home directory you won't have a Dockerfile and docker won't know what you want to build. Jun 26, 2019 at 19:08
  • Oh dear ... I just realised where I went wrong. When I cloned the kubernetes-engine-samples project from Github, I did this on my local machine rather than on the gcloud shell. I instinctively did it, because I'm just used to cloning projects locally on my machine. It's just a new concept for me to having to do everything on the cloud, including cloning projects. Sorry .. such a silly mistake. Thank you so much for your help.
    – Hazzaldo
    Jun 26, 2019 at 20:34
5

I also got the same error when running

docker build -t gcr.io/${PROJECT_ID}/hello-app:v1 .

but changing it to (my PROJECT_ID is say deepworld123)

docker build -t gcr.io/deepworld123/hello-app:v1 .

fixed it for me. Even though i did set PROJECT_ID=deepworld123.

0

Your tutorial link doesn't work (it's a link to a GCP dashboard, not a tutorial), but presumably there was a step where you were supposed to set the PROJECT_ID variable, which you skipped. The error message shows nothing between the two slashes where ${PROJECT_ID} appears in your command.

1
0

Had a very similar issue involving PROJECT_ID not being set correctly. The solution has to deal with formating as the error message says.

My PROJECT_ID string has the following format companyname.com:companyname-1 After I followed all the steps in the accepted answer the error message was the same.

It turns out the : needs to be replaced by a /. The final gcr.io string looks like:

gcr.io/companyname.com/companyname-1/hello-app:v1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.