0

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
jonathan-dev
  • 330
  • 1
  • 3
  • 16
  • How do you set the environment variables? – Hans Kilian May 26 '23 at 07:20
  • I update the post to include that information also. – jonathan-dev May 26 '23 at 07:29
  • 1
    The process substitution and environment expansion are happening in the shell on your host (in line 2, notice the error is coming from `zsh`) and you need to single-quote the `sh -c` string, not double-quote it. In the linked question, see especially [this answer](/a/34052766). – David Maze May 26 '23 at 09:50

0 Answers0