How to fix /bin/sh: [npm,: not found in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025· 160 views

This error occurs when the CMD or ENTRYPOINT instruction in a Dockerfile uses incorrect JSON array syntax. The fix is to ensure proper double quotes, commas between elements, and standard ASCII characters in the exec form.

Quick fix

Fixes /bin/sh: [npm,: not found

# Wrong: single quotes (JSON requires double quotes)
CMD ['npm', 'start']

# Wrong: missing commas
CMD ["npm" "start"]

# Wrong: no quotes at all
CMD [npm, start]

# Wrong: smart/curly quotes (often from copy-paste)
CMD [“npm”, “start”]

# Wrong: missing quotes on some elements
CMD ["npm", start]
  1. Identify the problematic instruction
  2. Fix the JSON array syntax
  3. Replace smart quotes if present
  4. Consider using shell form for simple commands
docker — error
# Wrong: single quotes (JSON requires double quotes)
CMD ['npm', 'start']
# Wrong: missing commas
CMD ["npm" "start"]
# Wrong: no quotes at all
CMD [npm, start]
# Wrong: smart/curly quotes (often from copy-paste)
CMD [“npm”, “start”]
# Wrong: missing quotes on some elements
CMD ["npm", start]
/bin/sh: [npm,: not found

What this error means

The "/bin/sh: [npm,: not found" error indicates that Docker failed to parse your CMD or ENTRYPOINT instruction as a valid JSON array. When the exec form (array syntax) cannot be parsed as JSON, Docker falls back to shell form, passing the entire string to /bin/sh -c. The shell then tries to execute "[npm," as a command, which doesn't exist. This happens because the exec form requires strict JSON syntax: double quotes around each element, commas between elements, and standard ASCII characters. Common mistakes include using single quotes, forgetting commas, omitting quotes entirely, or copying code from sources that use "smart quotes" (curly quotes) instead of straight quotes. The error message reveals the problem: "[npm," appears as if it's trying to run a command literally named "[npm," rather than parsing "npm" as the first element of a JSON array.

Typical symptoms

  • Container fails to start with '/bin/sh: [command,: not found' error
  • Docker build succeeds but container immediately exits with error
  • Error mentions '[npm,' or similar partial array syntax as not found
  • Works when running command manually inside container but fails on startup
  • Error appears after copying Dockerfile from documentation or blog posts

Common causes

  1. Using single quotes instead of double quotes in CMD/ENTRYPOINT array (JSON requires double quotes)
  2. Missing commas between array elements in CMD/ENTRYPOINT
  3. Using 'smart quotes' (curly quotes like “ ”) copied from word processors or websites
  4. Forgetting quotes entirely around array elements (CMD [npm, start] instead of CMD ["npm", "start"])
  5. Extra spaces inside quotes or missing spaces between elements
  6. Mixing shell form and exec form syntax incorrectly

How to fix "/bin/sh: [npm,: not found"

1Identify the problematic instruction

Open your Dockerfile and locate the CMD or ENTRYPOINT instruction. Look for syntax issues:

Common incorrect patterns:

dockerfile
# Wrong: single quotes (JSON requires double quotes)
CMD ['npm', 'start']

# Wrong: missing commas
CMD ["npm" "start"]

# Wrong: no quotes at all
CMD [npm, start]

# Wrong: smart/curly quotes (often from copy-paste)
CMD [“npm”, “start”]

# Wrong: missing quotes on some elements
CMD ["npm", start]

The error "/bin/sh: [npm,: not found" specifically indicates the array wasn't parsed as JSON, so Docker passed it to the shell literally.

2Fix the JSON array syntax

Correct the CMD or ENTRYPOINT to use valid JSON array syntax with standard double quotes and commas:

dockerfile
# Correct: double quotes and commas
CMD ["npm", "start"]

# Correct: with arguments
CMD ["npm", "run", "dev"]

# Correct: ENTRYPOINT with CMD
ENTRYPOINT ["node"]
CMD ["server.js"]

# Correct: running a script
CMD ["./start.sh"]

# Correct: with full path
CMD ["/usr/local/bin/npm", "start"]

Key rules for exec form:
- Use standard double quotes (") not single quotes or smart quotes
- Put a comma between each array element
- Each argument must be a separate array element
- The array is parsed as JSON, so follow JSON syntax strictly

3Replace smart quotes if present

If you copied your Dockerfile from a website, blog, or word processor, it may contain "smart quotes" that look similar but aren't valid JSON.

Check for smart quotes:
- Curly/smart quotes: “ ” ‘ ’
- Straight quotes (correct): " '

Fix using sed or your editor:

bash
# Replace smart quotes in Dockerfile
sed -i 's/[“”]/"/g' Dockerfile
sed -i "s/[‘’]/'/g" Dockerfile

In VS Code:
1. Open Find and Replace (Ctrl+H / Cmd+H)
2. Enable regex mode
3. Find: [“”] Replace: "
4. Click "Replace All"

Prevention: Always type Dockerfile commands manually or copy from plain text sources like official documentation or GitHub raw files.

4Consider using shell form for simple commands

If you don't need the benefits of exec form, you can use shell form instead, which is more forgiving:

dockerfile
# Shell form (no JSON parsing needed)
CMD npm start

# Shell form with multiple commands
CMD npm install && npm start

# Shell form allows variable expansion
CMD echo "Starting on port $PORT" && npm start

When to use shell form:
- Simple commands without signal handling requirements
- Commands that need shell features (pipes, variable expansion, globbing)
- Quick prototyping

When to use exec form (recommended for production):
- Proper signal handling (SIGTERM for graceful shutdown)
- No shell overhead
- Predictable argument parsing
- Docker best practice for CMD and ENTRYPOINT

5Test your fix

After fixing the syntax, rebuild and test your image:

bash
# Rebuild the image
docker build -t myapp .

# Run and verify it starts correctly
docker run myapp

# Or run interactively to debug if needed
docker run -it myapp /bin/sh

Verify the instruction was parsed correctly:

bash
# Inspect how Docker stored the CMD
docker inspect myapp --format='{{.Config.Cmd}}'

# Should show: [npm start] for exec form
# Not: [/bin/sh -c npm start] which indicates shell form fallback

If Docker shows /bin/sh -c wrapping your command, it means the exec form wasn't parsed correctly and fell back to shell form.

Advanced notes

Exec form vs Shell form internals: When you use exec form CMD ["npm", "start"], Docker directly executes the binary without a shell wrapper. The process runs as PID 1 and receives signals directly. Shell form CMD npm start runs as /bin/sh -c "npm start", meaning /bin/sh is PID 1 and may not forward signals to your application.

JSON parsing behavior: Docker's JSON parser is strict. If parsing fails, it silently falls back to shell form. This is why CMD ['npm', 'start'] (single quotes) doesn't error during build—Docker treats it as shell form, passing the literal string ['npm', 'start'] to /bin/sh.

Escaping special characters: If your command includes quotes or special characters, escape them properly:

dockerfile
# Running a command with JSON argument
CMD ["node", "-e", "console.log(\"Hello\")"]

# Or use shell form to avoid escaping
CMD node -e 'console.log("Hello")'

ENTRYPOINT + CMD combination: When both are in exec form, CMD arguments are appended to ENTRYPOINT:

dockerfile
ENTRYPOINT ["npm"]
CMD ["start"]
# Runs: npm start

# Override CMD at runtime:
# docker run myapp run test
# Runs: npm run test

Debugging parse issues: To see exactly how Docker interprets your instruction:

bash
docker history myapp --no-trunc | grep -E "CMD|ENTRYPOINT"

Windows considerations: On Windows containers, the default shell is cmd /S /C instead of /bin/sh -c. Use exec form for cross-platform Dockerfiles.

Frequently asked questions

What does "/bin/sh: [npm,: not found" mean?
The "/bin/sh: [npm,: not found" error indicates that Docker failed to parse your CMD or ENTRYPOINT instruction as a valid JSON array. When the exec form (array syntax) cannot be parsed as JSON, Docker falls back to shell form, passing the entire string to /bin/sh -c. The shell then tries to execute "[npm," as a command, which doesn't exist.
How do I fix "/bin/sh: [npm,: not found"?
This error occurs when the CMD or ENTRYPOINT instruction in a Dockerfile uses incorrect JSON array syntax. The fix is to ensure proper double quotes, commas between elements, and standard ASCII characters in the exec form.
What causes "/bin/sh: [npm,: not found"?
Using single quotes instead of double quotes in CMD/ENTRYPOINT array (JSON requires double quotes) Missing commas between array elements in CMD/ENTRYPOINT Using 'smart quotes' (curly quotes like “ ”) copied from word processors or websites
Is the "/bin/sh: [npm,: not found" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading