Given a spring boot app that writes files to /var/lib/app/files
.
I create an docker image with the gradle task:
./gradlew bootBuildImage --imageName=app:latest
Then, I want to use it in docker-compose
:
version: '3.5'
services:
app:
image: app:latest
volumes:
- app-storage:/var/lib/app/files
// ...ports etc
volumes:
app-storage:
This will fail, because the folder is created during docker-compose up
and is owned by root
and the app, hence, has no write access to the folder.
The quick fix is to run the image as root
by specifying user: root
:
version: '3.5'
services:
app:
image: app:latest
user: root # <------------ required
volumes:
- app-storage:/var/lib/app/files
// ...ports etc
volumes:
app-storage:
This works fine, but I do not want to run it as root
. I wonder how to achieve it? I normally could create a Dockerfile
that creates the desired folder with correct ownership and write permissions. But as far as I know build packs do not use a custom Dockerfile
and hence bootBuildImage
would not use it - correct? How can we create writable volumes then?