While trying to debug something I noticed that neither environment variables nor secrets were available when running a bash command on a swarm container. When running the commands in the -it
mode however I had access. Now I am looking for an explanation for that behavior since I wasn't able to find it in the docs yet.
The environment Variables are set in a swarm file like this:
secrets:
- influx_admin_token
environment:
- INFLUXDB_ADMIN_USER_TOKEN_FILE=/run/secrets/influx_admin_token
$ docker exec 0e40cc4ae32f /bin/bash -c "echo $(< /run/secrets/influx_admin_token)"
zsh: no such file or directory: /run/secrets/influx_admin_token
$ docker exec 0e40cc4ae32f /bin/bash -c "echo $INFLUXDB_ADMIN_USER_TOKEN_FILE "
$ docker exec -it 0e40cc4ae32f /bin/bash
I have no name!@0e40cc4ae32f:/$ echo $(< $INFLUXDB_ADMIN_USER_TOKEN_FILE)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx