# Choose the user PUID and PGID inside the container

**URL:** https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309
**Category:** Development
**Created:** [April 3, 2019, 7:24am UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309 "2019-04-03T07:24:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vitorl](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vitorl](https://meta.discourse.org/u/vitorl)
#### Post date: [April 3, 2019, 7:24am UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309/1 "2019-04-03T07:24:30Z")

</div>

Why isn’t there a way to choose the user PUID and PGID to avoid permission issues?

Also discourse is a public facing software, with user uploaded content so are stuff running as root by default?

There are many ways to fix this, from the Dockerfile itself, to post-boot scripts like s6-overlay.

I suggest creating a user called discourse inside the container and allowing us to start the docker with a variable like -e PUID=1020 then just run this simple shell command somewhere after boot:

> groupmod -o -g “$PGID” discourse \> /dev/null 2\>&1  
> usermod -o -u “$PUID” discourse \> /dev/null 2\>&1  
> chown -R discourse:discourse /any/folder/discourse/needs

That will fix permission issues on the host, add consistency, and improve security.

Because of this I can’t get discourse back online after chown my `/opt` directory which I store all my dockers and run all of them as any arbitrary user I want so I never have issues.

I have no way to guess which PID and GID the discourse container needs either. Not really good implementation.

Even after a rebuild, even if I rebuild as root, even if I rebuild as my docker user, the permissions are messed now, this could have been easily prevented with 2 variables and 3 shell commands after container boot.

I’m having the same issue as this guy after boot now…[Problem with docker installation](https://meta.discourse.org/t/problem-with-docker-installation/94700)

---

<div class="post-metadata">

### Author: ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)
#### Post date: [April 3, 2019, 2:59pm UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309/2 "2019-04-03T14:59:37Z")

</div>

> [@vitorl](#):
>
> so are stuff running as root by default?

Have you checked? There are multiple non-priviliged users for the different services in the container.

---

<div class="post-metadata">

### Author: ![vitorl](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vitorl](https://meta.discourse.org/u/vitorl)
#### Post date: [April 3, 2019, 9:56pm UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309/3 "2019-04-03T21:56:17Z")

</div>

If I can’t choose their PUID and PGID this means nothing. Permission issues will still happen, and people will have no idea what supposed user/PUID PGID it should be to fix it

---

<div class="post-metadata">

### Author: ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)
#### Post date: [April 3, 2019, 11:29pm UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309/4 "2019-04-03T23:29:49Z")

</div>

> [@vitorl](#):
>
> this means nothing

I don’t think that word means what you think in means. Or rather, “I don’t know how to change them” does not mean “they can’t be changed”.

> [@vitorl](#):
>
> I suggest creating a user called discourse inside the container and allowing us to start the docker with a variable like -e PUID=1020

Oh hey, there already is a user called discourse. Which user specifically do you suggest that environment variable change? Choose carefully because they all control important data.

There are six daemons running in the container – cron, nginx, postgres, redis, syslog, and unicorn. Each of them is started by a runit/runsvdir/runsv script in `/etc/service`.

The “official” method to modify a container is to add `run` and `replace` stanzas in the `app.yml` and rebuild. (This configuration system is called “pups” if you want to search the forum here for more details.)

For example, you’d change UID/GID for the redis server by modifying the last line in the script:

```plaintext
exec thpoff chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf

```

---

<div class="post-metadata">

### Author: ![vitorl](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vitorl](https://meta.discourse.org/u/vitorl)
#### Post date: [April 5, 2019, 11:48am UTC](https://meta.discourse.org/t/choose-the-user-puid-and-pgid-inside-the-container/113309/5 "2019-04-05T11:48:20Z")

</div>

I’d want every relevant user inside it to have the same PID/GID of my host user, is there any particular reason there are multiple users inside the container?

Regardless, it seems the only way to fix the permissions if you mess it is to do a clean install. How I am going to know which folder need to be owned by what PID/GID?

For now I removed `/discourse` from `/opt` because permission issues were bound to happen again and did a clean install. But really I’d just want simplicity, have a single user that runs everything with same PID/GID as my host or any arbitrary number…
