I'm a super novice vis-a-vis Docker, and recently moved a project from App Engine to Cloud Run. Was easy-peasy, loved it.
Now, however, I'm trying to update the image (since I added some new code). I understand that I need to get into an actual container to update an image (I think?) but when I attempt to docker run, I get an unexpected operator error.
It's driving me absolutely batty.
I can't start the container. I can't edit my image. I can't upload a new version on Cloud Run.
From what I can gather, an unexpected operator error has to deal with the Dockerfile. So, here's my Dockerfile (as given by Google for deploying an image on Cloud Run).
Dockerfile
#Use the official Node.js 10 image
#https://hub.docker.com/_/node
FROM node:10
#Create and change to the app directory
WORKDIR /usr/src/app
#Copy application dependency manifests to the container image.
#A wild card is used to ensure both package.json AND package-lock.json are copied.
#Copying this separately prevents re0running npm install on every code change.
COPY *package.json ./
#Install production dependences
RUN npm install --only=production
#COPY local code to the container image
COPY . .
#Run the web service on container startup
CMD [ "npm", "start" ]
The specific unexpected operator error I am getting is /bin/sh: 1: [: npm.: unexpected operator
I honestly don't know what to do at this point. I think I need a second set of eyes to just look it over.
I'm going to bet you cleaned up your code, intentionally or unintentionally, when you gave the code snippet CMD [ "npm", "start" ] It was almost certainly CMD [ "npm" "start" ]
when you initially built the image and tried running it as a container.
Breaking apart the error message: /bin/sh: 1: [: npm.: unexpected operator
It is telling you that the shell script is having an issue on line one. Which shell script? The shell script that's triggered by the CMD line. The line 1 part is because, taken in context of CMD running, that's the one and only line.
It's then saying, pretty illegibly that it's having an issue after the npm statement. The easiest way to accidentally cause that is to forget the comma.
Given that you were apparently able to get things running later, it's most likely that you:
I had this issue and I needed to use double quotes instead of single quotes at the CMD step in my Dockerfile
CMD [ "npm", "start" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With