0

I'm trying to customize a 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
executable
  • 3,365
  • 6
  • 24
  • 52

2 Answers2

1

you can try to run the commands directly:

RUN mkdir -p /data/local_data && chown -R abc:abc /data/local_data

you may try also to chabge your shebang to:

#!/bin/bash

to debugging you may try to set -xin your script a well.

EDIT:

I had notice this Removing intermediate container in your logs , the solution to it would be to use volume with your docker run command:

-v /path/your/new/folder/HOST:/path/your/new/folder/container
LinPy
  • 16,987
  • 4
  • 43
  • 57
  • I tried to run the commands directly and I got the same result – executable Jul 08 '19 at 09:13
  • is it a multi stage Dockerfile? could you please post your Dockerfile ? – LinPy Jul 08 '19 at 09:15
  • Here is the source of the image https://github.com/linuxserver/docker-nextcloud I'm using the base image. I also added the debug mod in the script and it output no error. The Dockerfile in my question is my full code – executable Jul 08 '19 at 09:15
  • This does not solve the original problem which is a volume handling issue, though the workaround your propose does provide result – Pierre B. Jul 08 '19 at 09:49
1

You are trying to modify a folder which is specified as a VOLUME in your base image, but as per Docker documentation on Volumes:

Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.

linuxserver/nextcloud does declare a volume /data which you are trying to change afterward, it's like doing:

VOLUME /data
...
RUN mkdir -p /data/local_data

The directory created will be discarded. You can however create your directory on container startup by modifying it's entrypoint so when container starts the directory is created. Currently linuxserver/nextcloud uses /init as entrypoint, so you can do:

Your script content which you then define as entrypoint:

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

# Call the base image entrypoint with parameters
/init "$@"

Dockerfile:

FROM linuxserver/nextcloud

# Copy the script and call it at entrypoint instead
COPY script /home/
ENTRYPOINT ["/home/script"]   
Pierre B.
  • 11,612
  • 1
  • 37
  • 58