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

树莓派迁移服务后Docker Compose报环境变量名称为空错误

容器启动报错:invalid environment variable: name cannot be empty

错误信息

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: invalid environment variable: name cannot be empty: unknown

镜像构建命令

sudo docker buildx build --load --platform linux/arm/v7 --build-arg JAR_FILE=basyx.components.AASServer-1.5.0.jar --build-arg PORT=4001 --tag aas-server:1.5.0-arm32v7 .

相关配置文件

Dockerfile

FROM adoptopenjdk/openjdk11

# Install dependency for wait-for-it-env.sh & wget for health check
RUN apt update && apt install -y jq && apt clean
RUN apt install -y wget

# Copy built jar to image using the jar name specified in the pom.xml (JAR_FILE)
ARG JAR_FILE
COPY wait-for-it-env-and-start-jar.sh /
# change EOL of .sh file to LF, so the unix container can find it
RUN ["sed", "-i", "s/
$//", "/wait-for-it-env-and-start-jar.sh"]
RUN ["chmod", "+x", "/wait-for-it-env-and-start-jar.sh"]

COPY target/${JAR_FILE} /usr/share/basyxExecutable.jar
COPY target/lib /usr/share/lib
COPY src/main/resources/aas.properties /usr/share/config/aas.properties
COPY src/main/resources/context.properties /usr/share/config/context.properties
COPY src/main/resources/mqtt.properties /usr/share/config/mqtt.properties
COPY src/test/resources/dockerMongodb.properties /usr/share/config/mongodb.properties

# Expose the appropriate port. In case of Tomcat, this is 8080.
ARG PORT
EXPOSE ${PORT} 4001

# Set the path for the aas configuration file
ARG AAS_CONFIG_KEY
ENV ${AAS_CONFIG_KEY} "/usr/share/config/aas.properties"

# Set the path for the context configuration file
ARG CONTEXT_CONFIG_KEY
ENV ${CONTEXT_CONFIG_KEY} "/usr/share/config/context.properties"

# Set the path for the mongodb configuration file
ARG MONGODB_CONFIG_KEY
ENV ${MONGODB_CONFIG_KEY} "/usr/share/config/mongodb.properties"

# Set the path for the mqtt configuration file
ARG MQTT_CONFIG_KEY
ENV ${MQTT_CONFIG_KEY} "/usr/share/config/mqtt.properties"

# Start the jar
ENTRYPOINT ["./wait-for-it-env-and-start-jar.sh"]

docker-compose.yml

services: 
  server:
    container_name: aas_server
    image: aas-server:1.5.0-arm32v7
    restart: always
    ports:
      - 8085:4001
    volumes:
      - /home/operation/dev/ICNAP_23_Digital_Twin/src/AAS/server:/usr/share/config

树莓派系统信息

  • Linux IOTpi2 5.10.63-v7l+ #1488 SMP Thu Nov 18 16:15:28 GMT 2021 armv7l GNU/Linux
  • PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
  • NAME="Raspbian GNU/Linux"
  • VERSION_ID="11"
  • VERSION="11 (bullseye)"
  • VERSION_CODENAME=bullseye
  • ID=raspbian
  • ID_LIKE=debian

解决方法

问题根源:Dockerfile中定义了AAS_CONFIG_KEY、CONTEXT_CONFIG_KEY等ARG参数,但构建镜像时没有传入这些参数的值,导致ENV ${AAS_CONFIG_KEY} ...被解析成了ENV "" "/usr/share/config/aas.properties"——环境变量名称为空,触发容器启动报错。

有两种解决方式:

  1. 构建时补充所有缺失的ARG参数
    修改构建命令,添加配置键参数,示例如下(可根据实际需求调整环境变量名称):

    sudo docker buildx build --load --platform linux/arm/v7 \
      --build-arg JAR_FILE=basyx.components.AASServer-1.5.0.jar \
      --build-arg PORT=4001 \
      --build-arg AAS_CONFIG_KEY=AAS_CONFIG_PATH \
      --build-arg CONTEXT_CONFIG_KEY=CONTEXT_CONFIG_PATH \
      --build-arg MONGODB_CONFIG_KEY=MONGODB_CONFIG_PATH \
      --build-arg MQTT_CONFIG_KEY=MQTT_CONFIG_PATH \
      --tag aas-server:1.5.0-arm32v7 .
    
  2. 固定环境变量名称,删除动态ARG
    如果不需要动态指定环境变量名称,直接在Dockerfile中写死变量名,替换原来的ARG+ENV块:

    ENV AAS_CONFIG_PATH "/usr/share/config/aas.properties"
    ENV CONTEXT_CONFIG_PATH "/usr/share/config/context.properties"
    ENV MONGODB_CONFIG_PATH "/usr/share/config/mongodb.properties"
    ENV MQTT_CONFIG_PATH "/usr/share/config/mqtt.properties"
    

    这样构建时无需传入额外ARG参数,避免空名称问题。

最后检查wait-for-it-env-and-start-jar.sh脚本,确保它能正确读取修改后的环境变量。


内容的提问来源于stack exchange,提问作者Maíra Matos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 13:43:20