# Bootsnap::CompileCache::PermissionError

**URL:** https://meta.discourse.org/t/bootsnap-permissionerror/181002
**Category:** Self-hosting
**Created:** [February 24, 2021, 1:13pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002 "2021-02-24T13:13:37Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![marek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marek/32/178390_2.png) [@marek](https://meta.discourse.org/u/marek)
#### Post date: [February 24, 2021, 1:13pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/1 "2021-02-24T13:13:37Z")

</div>

Hello, everyone. I have fresh installment of Discourse in Docker.  
So the problem is that after container rebuild, container is up and I can access app page. However, I get 502 as response. In logs or when I try accessing i.e. `rails c` (inside container) all I can see is this error:  
`permission\_error’: bootsnap doesn’t have permission to write cache entries in ‘tmp/cache/bootsnap/compile-cache’ (or, less likely, doesn’t have permission to read ‘/usr/local/lib/ruby/2.7.0/set.rb’) (Bootsnap::CompileCache::PermissionError)

In order to fix this I have to chown -R discourse:discourse /var/www/discourse/tmp (to be exact, it’s /var/www/discourse/tmp/cache/bootsnap) directory inside container, and right after app works fine even without restart. It’s quite obnoxious thing to do manually after each rebuild.

I was thinking that I can tackle it using custom commands section in app.yml with mentione above `chown -R discourse:discourse /var/www/discourse/tmp`, but unfortunately it doesn’t work. Commands seem to be called there (tried mkdir just to check), but file permissions are not affected.

What can be the issue here and how it can be resolved? Maybe there is some way to correctly change file permissions?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 24, 2021, 2:45pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/2 "2021-02-24T14:45:34Z")

</div>

That’s odd. Did you follow [Discourse official Standard Installation](https://meta.discourse.org/t/discourse-official-standard-installation/142537)?

---

<div class="post-metadata">

### Author: ![marek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marek/32/178390_2.png) [@marek](https://meta.discourse.org/u/marek)
#### Post date: [February 24, 2021, 2:46pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/3 "2021-02-24T14:46:34Z")

</div>

Of course. No additional steps were made.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 25, 2021, 12:38am UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/4 "2021-02-25T00:38:25Z")

</div>

Can you paste your container.yml file (sans passwords) ?

---

<div class="post-metadata">

### Author: ![marek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marek/32/178390_2.png) [@marek](https://meta.discourse.org/u/marek)
#### Post date: [February 25, 2021, 10:02am UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/5 "2021-02-25T10:02:15Z")

</div>

Sure. Here you are:

```plaintext
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80" # http
  - "443:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  #db_shared_buffers: "256MB"

  ## can improve sorting performance, but adds memory usage per-connection
  #db_work_mem: "40MB"

  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  #UNICORN_WORKERS: 3

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'example.com'

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'test@mail.com'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: smtp.mail.io
  #DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: 111
  DISCOURSE_SMTP_PASSWORD: 111
  #DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
  #DISCOURSE_SMTP_DOMAIN: discourse.example.com # (required by some providers)
  #DISCOURSE_NOTIFICATION_EMAIL: noreply@discourse.example.com # (address to send notifications from)

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  #LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: https://discourse-cdn.example.com
  
  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details
  #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  #- exec: chown -R discourse:discourse /var/www/discourse/tmp/cache/bootsnap # example command on how I'd tried to fix file permissions
  - exec: echo "End of custom commands"

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 25, 2021, 12:49pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/6 "2021-02-25T12:49:46Z")

</div>

You didn’t run `discourse-setup`, right? It should have defined some things that you have commented out. I just made those changes and want to be sure that it’s working as expected.

Is there a reason you’re not using let’s encrypt?

I don’t see an explanation for your problem, though.

---

<div class="post-metadata">

### Author: ![marek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marek/32/178390_2.png) [@marek](https://meta.discourse.org/u/marek)
#### Post date: [February 25, 2021, 12:55pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/7 "2021-02-25T12:55:39Z")

</div>

Firstly, application was built using discourse-setup. After few tries of rebuilding it and seeing no positive result, I moved to one of pre-defined .yml configs from /samples directory, and then simply edited out it with my credentials.  
Why not Let’s encrypt - asked to use client’s certificates. But as far as I understand - certificates have nothing to do with it, as they’re valid and there is no issue from it.  
The issue seems to be on project level, which is specifically related to bootsnap cache file permissions (maybe the issue is on the side of Bootsnap).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 25, 2021, 1:01pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/8 "2021-02-25T13:01:44Z")

</div>

> [@marek](#):
>
> simply edited out it with my credentials.  
> Why not Let’s encrypt - asked to use client’s certificates

Thanks. I agree that’s not likely to be the problem. I did a couple of installs yesterday that worked just fine. I don’t see any explanation for your problem.

---

<div class="post-metadata">

### Author: ![tebanep](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tebanep/32/187608_2.png) [@tebanep](https://meta.discourse.org/u/tebanep)
#### Post date: [March 3, 2021, 12:31am UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/9 "2021-03-03T00:31:55Z")

</div>

We were facing the same problem and I confirm that running (inside the docker container):

```
chown -R discourse:discourse /var/www/discourse/tmp

```

Fixed the problem! No restarts were required. The ‘tmp’ directory permissions were assigned to ‘discourse:www-data’ before the owner change. Hope this is something that in the future could be fixed so that this manual action won’t be needed after each rebuild.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 3, 2021, 12:47pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/10 "2021-03-03T12:47:51Z")

</div>

Are you running launcher as root?

---

<div class="post-metadata">

### Author: ![tebanep](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tebanep/32/187608_2.png) [@tebanep](https://meta.discourse.org/u/tebanep)
#### Post date: [March 4, 2021, 2:56pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/11 "2021-03-04T14:56:46Z")

</div>

Yes @pfaffman, I am. Is that the problem?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [March 4, 2021, 3:11pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/12 "2021-03-04T15:11:46Z")

</div>

> [@tebanep](#):
>
> Is that the problem?

I don’t think so. I’m always starting my self-hosted instances as root and have never seen a problem like that.

Who’s the owner of the directory if you don’t use `chown`? In a recently rebuilt container it looks like this:

```plaintext
# ls -l /var/www/discourse/tmp
total 36
lrwxrwxrwx 1 root root 19 Mar 2 14:56 backups -> /shared/tmp/backups
drwxr-xr-x 1 discourse discourse 4096 Mar 2 14:57 cache
drwxr-xr-x 1 discourse discourse 4096 Mar 2 14:57 ember-rails
drwxr-xr-x 1 discourse root 4096 Mar 2 15:04 pids
lrwxrwxrwx 1 root root 20 Mar 2 14:56 restores -> /shared/tmp/restores
drwxr-xr-x 2 discourse root 4096 Mar 2 14:56 sockets
drwxr-xr-x 2 discourse discourse 12288 Mar 2 15:02 stylesheet-cache

```

Did you add any custom commands or hooks to your `app.yml` besides cloning plugins?

---

<div class="post-metadata">

### Author: ![tebanep](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tebanep/32/187608_2.png) [@tebanep](https://meta.discourse.org/u/tebanep)
#### Post date: [March 4, 2021, 3:25pm UTC](https://meta.discourse.org/t/bootsnap-permissionerror/181002/13 "2021-03-04T15:25:55Z")

</div>

The owner user and group of the /var/www/discourse/tmp directory was **discourse:www-data** after launching the container. Reassigning to **discourse:discourse** solved the issue. This had not happened to me before and I’ve been using discourse for several months already. Anyway, it was an easy fix and might have been random, so I don’t want to bother you with it anymore. Thanks a lot @gerhard!
