How can we add UID and GID in stack file or compose file?

Hi Team,

how can we add UID and GID in stack file or compose file. I know we can use uid,gid and mode with secret in compose file and we can add user in Dockerfile but we want non-root user in compose file who can run the containers and services. We are using swarm mode and run the docker stack deploy command to create services.

You can specify the user that you want a service to run as in the docker-compose.yml file for a Swarm service.

user: myuser

Hi,
Thanks for reply. Can we add UID and GID there instead of username. Like we could for secret file.
uig: 1000
gid: 1001
mode: 0440

Actually yes.

user: uid:gid

1 Like

I found one article regarding this. But need to test it. As we are using docker stack deploy not compose-up