Search code examples
dockerdocker-composeraspberry-pi

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


I have a service that originally ran inside a Linux server, but now I need to make it work inside the raspberry pi.

After the necessary modifications to make it run inside the raspberry, docker compose no longer works.

The modifications I made were to change the base image to one that could be built and run inside the raspberry. The original image was openjdk11:11-slim-bullseyeslim but I changed to a more compatible version: adoptopenjdk/openjdk11.

When i try to run the docker compose there is this error output:

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

The command I am using to build the image, on this stage there is no problem:

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 .

The Dockerfile Im using to build the image:

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"]

The docker-compose file:

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

Raspberry especifications:

  • 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

I alredy tried diferents versions of the same image, but all the versions that I tried had the same output


Solution

  • Your ENV statements are weird.

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

    means "take the value of AAS_CONFIG_KEY and create an environment variable with that name and set it's value to /usr/share/config/aas.properties".

    When you don't pass a value for AAS_CONFIG_KEY during build (as your build statement shows that you don't), the name of the environment variable is empty and you end up with

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

    Then, when Docker tries to run the image, Docker fails and you get the error message "invalid environment variable: name cannot be empty: unknown".

    My guess is that you mean to set an environment variable called AAS_CONFIG_KEY and your ENV statement should be

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

    That allows you to set a value for AAS_CONFIG_KEY using --build-arg if you want. If you don't set it, /usr/share/config/aas.properties will be used as a default value.

    You need to make a similar change for the rest of your environment variables.