Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/nats] environment variables are empty when using docker-compose.yml to deployment #66439

Open
alexsunlee opened this issue May 8, 2024 · 8 comments
Assignees
Labels
in-progress nats tech-issues The user has a technical issue about an application

Comments

@alexsunlee
Copy link

alexsunlee commented May 8, 2024

Name and Version

bitnami/nats:latest

What architecture are you using?

Linux x86_64 ubuntu

What steps will reproduce the bug?

When I run docker compose up -d for my nats container, I found all environment varibles are empty. Yaml example is as follow.

services:
  nats:
    image: bitnami/nats:latest
    container_name: nats
    restart: always
    ports:
      - '4222:4222'
      - '6222:6222'
      - '8222:8222'
    environment:
      - NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx
      - NATS_CONF_FILE=${NATS_CONF_DIR}/nats.conf
      - NATS_EXTRA_ARGS=-js -n=dnsight-nats -sd=${NATS_DATA_DIR} -c ${NATS_CONF_DIR}/nats.conf --auth ${NATS_TOKEN}
    volumes:
      - /opt/dnsight/nats:${NATS_DATA_DIR}:rw
      - ./nats.conf:${NATS_CONF_DIR}/nats.conf

What is the expected behavior?

If I up this container my hand without any envirnment variables.

elon@mask:~/work$ docker run -ti --rm bitnami/nats /bin/bash
nats 06:57:23.81 INFO  ==> 
nats 06:57:23.81 INFO  ==> Welcome to the Bitnami nats container
nats 06:57:23.81 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
nats 06:57:23.81 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
nats 06:57:23.81 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
nats 06:57:23.82 INFO  ==> 

I have no name!@c06948e8700d:/opt/bitnami/nats$ env
NATS_PID_FILE=/opt/bitnami/nats/tmp/nats-server.pid
NATS_TLS_KEY_FILENAME=nats-server.key
NATS_INITSCRIPTS_DIR=/docker-entrypoint-initdb.d
NATS_TLS_CRT_FILENAME=nats-server.crt
NATS_FILENAME=nats-server
NATS_CLUSTER_SEED_NODE=
MODULE=nats
HOSTNAME=c06948e8700d
NATS_CLUSTER_ROUTES=
NATS_PASSWORD=
NATS_TOKEN=
BITNAMI_ROOT_DIR=/opt/bitnami
NATS_DAEMON_USER=nats
NATS_CLUSTER_USERNAME=nats
NATS_BIND_ADDRESS=0.0.0.0
PWD=/opt/bitnami/nats
OS_FLAVOUR=debian-12
NATS_DEFAULT_CLIENT_PORT_NUMBER=4222
NATS_CLUSTER_PASSWORD=
NATS_EXTRA_ARGS=
NATS_DEFAULT_HTTPS_PORT_NUMBER=8443
NATS_CONF_DIR=/opt/bitnami/nats/conf
NATS_MOUNTED_CONF_DIR=/bitnami/nats/conf
NATS_DATA_DIR=/bitnami/nats/data
NATS_TMP_DIR=/opt/bitnami/nats/tmp
HOME=/
NATS_ENABLE_AUTH=no
NATS_CLIENT_PORT_NUMBER=4222
NATS_CONF_FILE=/opt/bitnami/nats/conf/nats-server.conf
NATS_DEFAULT_BIND_ADDRESS=0.0.0.0
BITNAMI_DEBUG=false
NATS_DEFAULT_CLUSTER_PORT_NUMBER=6222
NATS_HTTP_PORT_NUMBER=8222
NATS_BASE_DIR=/opt/bitnami/nats
TERM=xterm
NATS_DEFAULT_HTTP_PORT_NUMBER=8222
NATS_ENABLE_CLUSTER=no
NATS_USERNAME=nats
SHLVL=1
NATS_LOGS_DIR=/opt/bitnami/nats/logs
BITNAMI_VOLUME_DIR=/bitnami
BITNAMI_APP_NAME=nats
NATS_BIN_DIR=/opt/bitnami/nats/bin
NATS_LOG_FILE=/opt/bitnami/nats/logs/nats-server.log
NATS_ENABLE_TLS=no
NATS_CLUSTER_PORT_NUMBER=6222
NATS_DEFAULT_CONF_DIR=/opt/bitnami/nats/conf.default
APP_VERSION=2.10.14
NATS_CLUSTER_TOKEN=
OS_NAME=linux
PATH=/opt/bitnami/nats/bin:/opt/bitnami/common/bin:/opt/bitnami/common/bin:/opt/bitnami/nats/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NATS_HTTPS_PORT_NUMBER=8443
NATS_DAEMON_GROUP=nats
OS_ARCH=amd64
NATS_VOLUME_DIR=/bitnami/nats
_=/usr/bin/env

What do you see instead?

after up yaml, the command line's output as follow

elon@mask:~/work$ docker compose up -d nats
WARN[0000] The "NATS_DATA_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_DATA_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_TOKEN" variable is not set. Defaulting to a blank string. 
1 error(s) decoding:

* error decoding 'volumes[0]': invalid spec: /opt/dnsight/nats::rw: empty section between colons

All environments variables are empty, so, why?

Additional information

I was saw the document from README, environment variables have two type, one is writable variables, and another is read only, I think the read only one should not be replaced. The only reason I think is the file /opt/bitnami/scripts/nats-env.sh is not work.

Thanks a lot for helping me to solving this problem.

@alexsunlee alexsunlee added the tech-issues The user has a technical issue about an application label May 8, 2024
@github-actions github-actions bot added the triage Triage is needed label May 8, 2024
@alexsunlee alexsunlee changed the title bitnami/nats environment is empty when using docker-compose.yml to deployment bitnami/nats environment variables are empty when using docker-compose.yml to deployment May 8, 2024
@javsalgar javsalgar changed the title bitnami/nats environment variables are empty when using docker-compose.yml to deployment [bitnami/nats] environment variables are empty when using docker-compose.yml to deployment May 8, 2024
@github-actions github-actions bot removed the triage Triage is needed label May 8, 2024
@github-actions github-actions bot assigned jotamartos and unassigned javsalgar May 8, 2024
@jotamartos
Copy link
Contributor

Hi @alexsunlee,

I just tried to reproduce the issue but I couldn't do so. I made this change in the default docker-compose.yml file

diff --git a/bitnami/nats/docker-compose.yml b/bitnami/nats/docker-compose.yml
index b811cefad3b..db73c168c60 100644
--- a/bitnami/nats/docker-compose.yml
+++ b/bitnami/nats/docker-compose.yml
@@ -10,3 +10,6 @@ services:
       - '4222:4222'
       - '6222:6222'
       - '8222:8222'
+    environment:
+      - NATS_ENABLE_AUTH=true
+      - NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx

and confirmed that the token was properly set in the container

$ docker-compose exec nats env | grep NATS_TOKEN
NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx
$ docker-compose exec nats cat /opt/bitnami/nats/conf/nats-server.conf
# host/port to listen for client connections
listen: 0.0.0.0:4222
# host/port for HTTP monitoring
http: 0.0.0.0:8222
# host/port for HTTPS monitoring
# https: 0.0.0.0:8443

# Logging options
debug: false
log_file: "/opt/bitnami/nats/logs/nats-server.log"

# Pid file
pid_file: "/opt/bitnami/nats/tmp/nats-server.pid"

# Authorization for client connections
authorization {
  timeout: 1
  token: "6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx"
}

@alexsunlee
Copy link
Author

alexsunlee commented May 10, 2024

Hi @alexsunlee,

I just tried to reproduce the issue but I couldn't do so. I made this change in the default docker-compose.yml file

diff --git a/bitnami/nats/docker-compose.yml b/bitnami/nats/docker-compose.yml
index b811cefad3b..db73c168c60 100644
--- a/bitnami/nats/docker-compose.yml
+++ b/bitnami/nats/docker-compose.yml
@@ -10,3 +10,6 @@ services:
       - '4222:4222'
       - '6222:6222'
       - '8222:8222'
+    environment:
+      - NATS_ENABLE_AUTH=true
+      - NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx

and confirmed that the token was properly set in the container

$ docker-compose exec nats env | grep NATS_TOKEN
NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx
$ docker-compose exec nats cat /opt/bitnami/nats/conf/nats-server.conf
# host/port to listen for client connections
listen: 0.0.0.0:4222
# host/port for HTTP monitoring
http: 0.0.0.0:8222
# host/port for HTTPS monitoring
# https: 0.0.0.0:8443

# Logging options
debug: false
log_file: "/opt/bitnami/nats/logs/nats-server.log"

# Pid file
pid_file: "/opt/bitnami/nats/tmp/nats-server.pid"

# Authorization for client connections
authorization {
  timeout: 1
  token: "6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kxxx"
}

Hi @jotamartos,
Thanks for your reply, but I think you did not understand what I mean.
I mean if you set env variables in docker-compose.yaml file, and then you enter the container, and use env, you will see all read only variables are gone. For this reason, if you set some variables in docker-compose.yml, it will prompt errors like this.

elon@mask:~/work$ docker compose up -d nats
WARN[0000] The "NATS_DATA_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_DATA_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_CONF_DIR" variable is not set. Defaulting to a blank string. 
WARN[0000] The "NATS_TOKEN" variable is not set. Defaulting to a blank string. 
1 error(s) decoding:

* error decoding 'volumes[0]': invalid spec: /opt/dnsight/nats::rw: empty section between colons

@jotamartos
Copy link
Contributor

You have an error in the docker-compose.yml file and that's why the deployment fails

  • error decoding 'volumes[0]': invalid spec: /opt/dnsight/nats::rw: empty section between colons

Please set the path to mount the volume as "NATS_DATA_DIR" is not available in your local machine.

@alexsunlee
Copy link
Author

You have an error in the docker-compose.yml file and that's why the deployment fails

  • error decoding 'volumes[0]': invalid spec: /opt/dnsight/nats::rw: empty section between colons

Please set the path to mount the volume as "NATS_DATA_DIR" is not available in your local machine.

The full docker-compose.yaml

services:
    nats:
        image: bitnami/nats:latest
        container_name: dnsight-nats
        restart: always
        ports:
          - '4222:4222'
          - '6222:6222'
          - '8222:8222'
        environment:
          - NATS_TOKEN=6DFVC5hthwVvd6c8rsbKPOouSdD9qh0kDggTghrV48XDb9Q4q1AkrXTrBWh3OL27
          - NATS_CONF_FILE=${NATS_CONF_DIR}/nats.conf
          - NATS_EXTRA_ARGS=-js -n=dnsight-nats -sd=${NATS_DATA_DIR} -c ${NATS_CONF_DIR}/nats.conf --auth ${NATS_TOKEN}
        volumes:
          - /opt/dnsight/nats:${NATS_DATA_DIR}:rw
          - ./nats.conf:${NATS_CONF_DIR}/nats.conf
        # networks:
        #  - dnsight-network

the nats.conf

# host/port to listen for client connections
listen: 0.0.0.0:4222
# host/port for HTTP monitoring
http: 0.0.0.0:8222
# host/port for HTTPS monitoring
# https: 0.0.0.0:8443

# Logging options
debug: false
log_file: "/data/logs/nats-server.log"

# Pid file
pid_file: "/data/tmp/nats-server.pid"

jetstream {
    store_dir: /data/jetstream
    max_mem: 512M
    max_file: 1G
}

accounts: {
    USERS: {
        users: [{user: dnsight, password: nats}]
        jetstream: enabled
    },
    SYS: {
        users: [{user: admin, password: nimda}]
    },
}
system_account: SYS

because the variables are empty, so, the errors are like this

* error decoding 'volumes[0]': invalid spec: /opt/dnsight/nats::rw: empty section between colons

@jotamartos
Copy link
Contributor

You can't use env vars to specify the directory to copy the volume to. Please take a look at this section of the documentation if you want to mount a custom conf file

https://github.com/bitnami/containers/tree/main/bitnami/nats#full-configuration

@alexsunlee
Copy link
Author

You can't use env vars to specify the directory to copy the volume to. Please take a look at this section of the documentation if you want to mount a custom conf file

https://github.com/bitnami/containers/tree/main/bitnami/nats#full-configuration

I have updated my docker-compose.yml

    image: bitnami/nats:latest
    container_name: dnsight-nats
    restart: always
    ports:
      - '4222:4222'
      - '6222:6222'
      - '8222:8222'
    environment:
      - NATS_EXTRA_ARGS=-js -n=dnsight-nats -sd=${NATS_DATA_DIR} #-c ${NATS_CONF_DIR}/nats.conf
    volumes:
      # - /opt/dnsight/nats:${NATS_DATA_DIR}:rw
      - ./nats.conf:/bitnami/nats/conf/nats.conf
    networks:
      - dnsight-network

and successed to run docker, and I entered it.

elon@mask:~/work$ docker exec -ti nats /bin/bash
I have no name!@7744e811ca49:/opt/bitnami/nats$ env
HOSTNAME=7744e811ca49
PWD=/opt/bitnami/nats
OS_FLAVOUR=debian-12
NATS_EXTRA_ARGS=-js -n=dnsight-nats -sd=
HOME=/
TERM=xterm
SHLVL=1
BITNAMI_APP_NAME=nats
APP_VERSION=2.10.14
OS_NAME=linux
PATH=/opt/bitnami/common/bin:/opt/bitnami/nats/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
OS_ARCH=amd64
_=/usr/bin/env

my question is, where is read only environment variables? you see the NATS_DATA_DIR is empty.

@alexsunlee
Copy link
Author

what I totally mean is, if I set environment in docker-compose.yml file, the readonly variables are gone. but if I just run command docker run -ti bitnami/nats:latest /bin/bash and env, the readonly is Ok, you can try it by yourself.

So, I think is the file /opt/bitnami/scripts/nats-env.sh is not working when I usingdocker-compose.yml to deploy.

@jotamartos
Copy link
Contributor

Hi @alexsunlee,

You are mixing things up and that's why you think that the container doesn't work properly but that's not the case. Let me explain.

The nats-env.sh script is loaded when executing different actions in the container, for example when starting the service

https://github.com/bitnami/containers/blob/main/bitnami/nats/2/debian-12/rootfs/opt/bitnami/scripts/nats/run.sh

The nats-env.sh script allows you edit the different env vars by providing then as environment variables when launching the container. The service will use your value instead of the default one we configure in the script.

You see all env vars when executing the docker run command because during the creation of the docker-image, those env vars are loaded

https://github.com/bitnami/containers/blob/main/bitnami/nats/2/debian-12/Dockerfile

However, if you execute docker-compose exec, you create a new connection to the container, one that is not a continuation of the Dockerfile and that's why you do not see all env vars but the service is using them as I explained above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-progress nats tech-issues The user has a technical issue about an application
Projects
None yet
Development

No branches or pull requests

3 participants