How to customize Dockerfile

I’m trying to customize the nextcloud Dockerfile, I just want to create a folder and assign the user (PID and GID) on the new folder.

Here is my full Dockerfile :

FROM linuxserver/nextcloud

COPY script /home/
RUN /home/script

The content of the script file :

#!/bin/sh
mkdir -p /data/local_data
chown -R abc:abc /data/local_data

I gave him the following permission : chmod +x script

At this moment it doesn’t create the folder, and I see no error in logs.

Command to run the container :

docker run -d \
  --name=nextcloud \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/Paris \
  -p 443:443 \
  -p 8080:80 \
  -v /home/foouser/nextcloud:/config \
  -v /home/foouser/data:/data \
  --restart unless-stopped \
  nextcloud_custom

Logs from build :

Step 1/3 : FROM linuxserver/nextcloud
 ---> d1af592649f2
Step 2/3 : COPY script /home/
 ---> 0b005872bd3b
Step 3/3 : RUN /home/script
 ---> Running in 9fbd3f9654df
Removing intermediate container 9fbd3f9654df
 ---> 91cc65981944
Successfully built 91cc65981944
Successfully tagged nextcloud_custom:latest

I found how to do it. I needed to map a volume to my new folder and keep the original image. Here is my command :

docker run -d \
  --name=nextcloud \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/Paris \
  -p 443:443 \
  -p 8080:80 \
  -v /home/foouser/nextcloud:/config \
  -v /home/foouser/data:/data/local_data \
  --restart unless-stopped \
  linuxserver/nextcloud