apache / apache/netbeans

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

Open
#9,559 0 comments 0 reactions 0 assignees View on GitHub
Docker kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### 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:
```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:
```bash
docker build --build-arg SKIP_TESTS=true -t myproject .
```
command to run (using .env variables) :
```bash
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

2) create a Dockerfile in same root of pom.xml

```dockerfile
# 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"]
```

3) from Dockerfile, right click, BUILD.... and create the image

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

5) from Browser: http://localhost:8080/

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

[HelloDocker.zip](https://github.com/user-attachments/files/30987045/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

Contributor guide

Open the contributing guide

Research direction

Start with the Services > Docker image Run dialog and compare its available inputs with the documented `docker run -p 8080:8080 --env-file .env myproject` command. Use the supplied Dockerfile, `.env`, and HelloDocker reproduction to verify that running the image passes MSG from `.env` to `System.getenv("MSG")`.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java
Domain
devops, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.