Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.4K
Vistas
How to fix Docker Unexpected Operator Error?

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.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

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:

  • Built the image from the Dockerfile with the missing comma
  • Tried running the image as a container and it didn't work because of the broken CMD in the built image
  • Fixed the error
  • Tried running the still broken image as the container and it didn't still didn't work as you were using the same image
  • Posted your code here, now with the fix in place but seeming to not work because you were still running the old image
  • Got advice here including trying a rebuild
  • Rebuilt a new image from the Dockerfile, picking up the fixed comma
  • Ran the new image as a container and everything seemed to magically fix
over 4 years ago · Santiago Trujillo Denunciar

0

You have to rebuild the image from Dockerfile after every change

docker build --tag="npm_app:latest" -f Dockerfile .
docker run npm_app 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda