An Environment Variable Gotcha with Docker Entrypoints

Published on 2026-08-02 by Emma Juettner

I recently encountered an interesting quirk of handling environment variables while using Docker and wanted to record it here in case it proves useful again in the future, either to me or to someone else.

Let's suppose I have a Java application which prints out the value of two environment variables, like so:

public class MyApp {

    public static void main(String[] args) {
        String myDottedVariableValue = System.getenv("my.dotted.variable");
        System.out.println("my.dotted.variable=" + myDottedVariableValue);

        String myUnderscoredVariableValue = System.getenv("my_underscored_variable");
        System.out.println("my_underscored_variable=" + myUnderscoredVariableValue);
    }
}

Note that one of my variables has dots in it. This is pretty conventional for system properties in the Java/Spring ecosystem. So let's say I'm running this Java application in a Docker image. What will I see at runtime?

Let's start by running our class in an Eclipse Temurin Docker base image with an exec form entrypoint:

FROM eclipse-temurin:25
COPY MyApp.class .
ENTRYPOINT ["java", "MyApp"]

When I build and run the image with a value provided for both variables:

docker build --tag 'my_image' -f Dockerfile . && docker run -e my.dotted.variable=dotted -e my_underscored_variable=underscored my_image:latest

This is what I get:

my.dotted.variable=dotted
my_underscored_variable=underscored

So both variable values are passed along for the Java application to use.

Now let's change up the Dockerfile to use a shell form entrypoint instead:

FROM eclipse-temurin:25
COPY MyApp.class .
ENTRYPOINT java MyApp

Now I'll execute the exact same command to build/run the Docker image again:

docker build --tag 'my_image' -f Dockerfile . && docker run -e my.dotted.variable=dotted -e my_underscored_variable=underscored my_image:latest

And here's the output I get at runtime:

my.dotted.variable=null
my_underscored_variable=underscored

Suddenly my dotted variable is null! As it turns out, if you run your entrypoint through the shell, the shell may not pass along environment variables that are not named the way it expects. In a POSIX-compliant shell, environment variables are not supposed to have dots in them. And so our improperly named variable vanishes, while our other variable is passed along just fine.