Docker:无效的环境变量:name 不能为空:未知

Docker: invalid environment variable: name cannot be empty: unknown

提问人:Maíra Matos 提问时间:11/15/2023 更新时间:11/16/2023 访问量:38

问:

我有一个最初在 Linux 服务器中运行的服务,但现在我需要让它在树莓派中工作。

经过必要的修改以使其在树莓园内运行后,docker compose 不再有效。

我所做的修改是将基础映像更改为可以在覆盆子中构建和运行的映像。原始映像是 openjdk11:11-slim-bullseyeslim,但我更改为更兼容的版本:adoptopenjdk/openjdk11。

当我尝试运行docker compose时,出现以下错误输出:

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/\r$//", "/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 文件:

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 2021 年 11 月 18 日星期四 16:15:28 GMT armv7l GNU/Linux
  • PRETTY_NAME=“Raspbian GNU/Linux 11 (靶心)”
  • NAME=“Raspbian GNU/Linux”
  • VERSION_ID=“11”
  • VERSION=“11(靶心)”
  • VERSION_CODENAME=靶心
  • ID=raspbian
  • ID_LIKE=debian

我尝试了同一图像的不同版本,但我尝试的所有版本都具有相同的输出

docker docker-compose 树莓派

评论

0赞 David Maze 11/15/2023
请注意 Dockerfile ENV 的语法:它是 或 ,名称周围没有标点符号,值周围没有引号。您可能不需要在映像中传递固定路径名作为构建时,我还建议删除这些行。ENV name valueENV name=valueARGARG

答:

2赞 Hans Kilian 11/16/2023 #1

你的 ENV 陈述很奇怪。

ENV ${AAS_CONFIG_KEY} "/usr/share/config/aas.properties"

意思是“获取 AAS_CONFIG_KEY 的值并创建一个具有该名称的环境变量,并将其值设置为 /usr/share/config/aas.properties”。

如果在生成过程中没有传递 AAS_CONFIG_KEY 的值(正如 build 语句所示),则环境变量的名称为空,最终会得到

ENV =/usr/share/config/aas.properties

然后,当 Docker 尝试运行映像时,Docker 失败,并且您收到错误消息“无效的环境变量:名称不能为空:未知”。

我的猜测是,您的意思是设置一个名为 AAS_CONFIG_KEY 的环境变量,您的 ENV 语句应该是

ENV AAS_CONFIG_KEY ${AAS_CONFIG_KEY:-"/usr/share/config/aas.properties"}

这允许您根据需要为 AAS_CONFIG_KEY using 设置一个值。如果不设置它,将用作默认值。--build-arg/usr/share/config/aas.properties

您需要对其余的环境变量进行类似的更改。