How to setup userid when run docker deploy stack

I create a general user, let’s say swarm-user, on each node of swarm cluster. let’s assume user id of swarm-user on node1 is uid1, on node2 is uid2.

test docker-compose.yml is blow:
version: “3.7”
services:

mysql:
image: mysql:5.7
user: ${userid}
//something else

then I run
userid=$(id -u swarm-user) sudo docker stack deploy -c docker-compose.yml mysql

but it turns out that in mysql task machine, this docker’s process user is not swarm-user.

what happened? how do I set userid dynamically when deploy stack?

Hi, can you try and hardcode the userid? because it should work

the thing is: I can’t hardcode since userid in different node is different. which one should I use?

can anybody help to look at this issue?

maybe just put something random in it, im just curious if its because the env variable is not being read.

Have you tried “export userid=…” ?