Docker Community Forums

Share and learn in the Docker community.

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


(Dipanjan) #1

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.


(Gary Forghetti) #2

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


(Dipanjan) #3

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


(Gary Forghetti) #4

Actually yes.

user: uid:gid


(Dipanjan) #5

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