Skip to content

Docker Service not able to read system variables from .env file while launch RUN from a Docker image #9559

Description

@millo74

Apache NetBeans version

Apache NetBeans 31

What happened

Hi!
I find very useful the panel Services > Docker, where you can easily see and manage Images and Containers.
before explaining the problem, a little premise.
Today's security best practices suggest to use a .env file to store env-variables that is better not to include into a artifact (war/jar),
and that normally are managed by Kubernetes via Secrets: a classical example are DB variables (DB_URL, DB_USER, DB_PWD)

And here is the problem.
if you just use terminal/console to build and run a Docker project, you can tell Docker to use this .env file.
for example:

Dockerfile:

	# BUILD #############################################
	FROM eclipse-temurin:17-jre-alpine
	WORKDIR /app
	COPY target/MyProj-0.0.1.jar app.jar
	COPY .env .env
	# RUN #############################################
	EXPOSE 8080
	ENTRYPOINT ["java", "-jar", "app.jar"]

command to build:

	docker build --build-arg SKIP_TESTS=true -t myproject .

command to run (using .env variables) :

	docker run -p 8080:8080 --env-file .env myproject

so my step on Netbeans simply are these 2:

  1. from Dockerfile, right click, Build... , fill all required fields, and everything is ok, creating new IMAGE under Docker images tree interface.
  2. from this new image, right click, Run...

and that's the point: when Run start, the .env variables are ignored
I dont know in Run Dialog, how to add extra param "--env-file .env" ; I've tried in Command input box, but nothing happen, or maybe I write something wrong into this filed.

Can anybody help me to understand if I've made mistakes, or the .env feature is missing in the current Docker Service?
thanks!

Language / Project Type / NetBeans Component

Java Maven Web application project

How to reproduce

with dockers running, simply create a java web project that simply print a System.getenv("MSG"):

  1. create a .env file with this content:

MSG=johnDoe123

  1. create a Dockerfile in same root of pom.xml
	# BUILD #############################################
	FROM eclipse-temurin:17-jre-alpine
	WORKDIR /app
	COPY target/HelloDocker-0.0.1.jar app.jar
	COPY .env .env
	# RUN #############################################
	EXPOSE 8080
	ENTRYPOINT ["java", "-jar", "app.jar"]
  1. from Dockerfile, right click, BUILD.... and create the image

  2. in Services > Docker > Local Docker > Images > HelloDocker, right click, RUN ... and complete.

  3. from Browser: http://localhost:8080/

and you can see that values is not the one stored in .env file

HelloDocker.zip

Did this work correctly in an earlier version?

No / Don't know

Operating System

windows 11

JDK

26, but build with 17 version

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

it occurs always, because I think is a missing feature

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dockerkind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions