You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Dockerfile中添加GITHUB_KEY与GITHUB_SECRET?命令执行报错求助

Fixing the Dockerfile CMD Syntax Error: Unterminated quoted string

Hey there! Let's break down what's going wrong with your CMD command and get it working correctly.

First, let's spot the issues in your original line:

  • You’re using Chinese quotation marks (“” instead of standard English ""), which the shell doesn’t recognize as valid quote delimiters—this is the immediate cause of the "Unterminated quoted string" error.
  • The CMD ["bash", ...] exec format doesn’t support inline environment variable assignments like GITHUB_KEY="..." directly in the argument list. Exec mode runs the command directly without a shell, so shell-specific syntax like variable assignment won’t be parsed here.

Solution 1: Use Shell Format for CMD

The simplest fix is to switch to the shell format of CMD (no square brackets), which lets you use shell syntax for environment variables:

CMD GITHUB_KEY="######" GITHUB_SECRET="##########" ./script/server

This runs the command through /bin/sh, which handles the variable assignments correctly. Just make sure to stick with English double quotes for your secrets.

If you prefer using the exec format (better practice because it avoids extra shell processes and lets your script run as PID 1), set the environment variables explicitly first with ENV, then run your command:

ENV GITHUB_KEY="######"
ENV GITHUB_SECRET="##########"
CMD ["./script/server"]

This keeps your environment variables clearly defined and makes your Dockerfile more readable.

Solution 3: Exec Format with Shell Wrapper

If you need to set variables only for the specific command (not globally in the container), wrap the command in sh -c within the exec format:

CMD ["sh", "-c", "GITHUB_KEY='######' GITHUB_SECRET='##########' ./script/server"]

Here, we use single quotes inside the command string to avoid conflicting with the outer double quotes, and sh -c tells the shell to execute the entire command line.

Any of these three approaches will fix the syntax error and get your container running properly.

内容的提问来源于stack exchange,提问作者Zero

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:53:35