How do you run a gocd/server container in docker with a bind mount /godata with the proper read/write permission using docker-compose?

I’m trying to run a gocd server using docker-compose, with a persistent data directory located at /godata on my host machine, but gocd is unable to write to files in this directory, even though I have granted read/write to user ‘go’.

Here’s my docker-compose.yml

  gocd:
    image: gocd/gocd-server:v19.7.0
    container_name: gocd
    ports:
      - "8153:8153"
      - "8154:8154"
    volumes:
     - type: bind
       target: /godata
       source: /godata

The documentation says to ensure that user ‘go’ has the proper permissions for bind mounts, or uid 1000.

Here’s a print out of permissions for the ‘go’ user:

drwxr-xr-x  2 go     go   4096 Jul  8 18:26 addons
drwxr-xr-x  3 go     go   4096 Jul 19 18:53 artifacts
drwxr-xr-x  2 go     go   4096 Jul 10 21:22 config
drwxr-xr-x  6 go     go   4096 Jul  8 18:27 db
drwxr-xr-x  2 go     go   4096 Jul 22 19:38 logs
drwxr-xr-x  4 go     go   4096 Jul  8 18:27 plugins

Tried to also grant permissions for uid 1000 using chmod 1000:go /godata.

I’m still getting write permission errors when running docker-compose up:

gocd                                 | jvm 1    | 14:40:05,993 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[PerformanceFileAppender] - Active log file name: logs/go-server-perf.log
gocd                                 | jvm 1    | 14:40:05,993 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[PerformanceFileAppender] - File property is set to [logs/go-server-perf.log]
gocd                                 | jvm 1    | 14:40:05,993 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[PerformanceFileAppender] - openFile(logs/go-server-perf.log,true) call failed. java.io.FileNotFoundException: logs/go-server-perf.log (Permission denied)
gocd                                 | jvm 1    |       at java.io.FileNotFoundException: logs/go-server-perf.log (Permission denied)
gocd                                 | jvm 1    |       at      at java.base/java.io.FileOutputStream.open0(Native Method)
gocd                                 | jvm 1    |       at      at java.base/java.io.FileOutputStream.open(Unknown Source)
gocd                                 | jvm 1    |       at      at java.base/java.io.FileOutputStream.<init>(Unknown Source)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:26)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:204)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.FileAppender.start(FileAppender.java:127)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.rolling.RollingFileAppender.start(RollingFileAppender.java:100)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
gocd                                 | jvm 1    |       at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
gocd                                 | jvm 1    |       at      at com.thoughtworks.go.logging.LogConfigurator.configureWith(LogConfigurator.java:122)
gocd                                 | jvm 1    |       at      at com.thoughtworks.go.logging.LogConfigurator.initialize(LogConfigurator.java:91)
gocd                                 | jvm 1    |       at      at com.thoughtworks.go.server.util.GoLauncher.main(GoLauncher.java:40)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at java.base/java.lang.reflect.Method.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at com.thoughtworks.gocd.Boot.run(Boot.java:89)
gocd                                 | jvm 1    |       at      at com.thoughtworks.gocd.Boot.main(Boot.java:55)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at java.base/java.lang.reflect.Method.invoke(Unknown Source)
gocd                                 | jvm 1    |       at      at org.tanukisoftware.wrapper.WrapperJarApp.run(WrapperJarApp.java:451)
gocd                                 | jvm 1    |       at      at java.base/java.lang.Thread.run(Unknown Source)

Source: StackOverflow