With -v missing files

Hi, im new to make a docker so this is probably a simple question.

my dockerfile includes this entry

COPY guide2go.sh /config/guide2go.sh

the file gets copied as supposed, but when i do the following in docker run command

-v ‘/mnt/user/appdata/guide2go2/’:’/config’:‘rw’

the file is gone … also inside the docker a

ls -la /config shows a empty folder

as soon i remove the -v mount from docker run its there …

/ # ls -la /config/
total 4
drwxr-xr-x 1 root root 22 Jul 10 09:13 .
drwxr-xr-x 1 root root 204 Jul 10 12:29 …
-rwxr-xr-x 1 root root 803 Jul 9 11:50 guide2go.sh
/ #

may a Tipp what i am doing wrong, thanks ahead

what i already tested

ADD instead COPY
different ways to ADD or COPY like making the file structure local and do
COPY . /

always with the same result

What is in this folder: /mnt/user/appdata/guide2go2/ ?
Because, since you mount this into the container, then the host is the “master” and the original content of /config will be overwritten

its empty, i d like to get the file from docker visible and editable in there …

and as i use some dockers where it is like this i wonder if theres another approach to achieve this ?

Yes there is! I guess you have a entrypoint or cmd defined.
You can as a entrypoint script, make it cp the file from a temp location, to the /config folder.

The entrypoint script will then copy the file when the container starts

Hope it makes sense

sure, but i already need the CMD to keep the docker alive as its a cron only …

or can i use CMD and ENTRYPOINT together with 2 different tasks ?

i ll try and see if it works.

Thanks for the hint.

i would make a script, that copies the file, and then just executes the command you need to run in the foreground ( in this case cron ) as the last thing the script does

Thanks

currently i have a entrypoint script like this and looking ok so far

may u have a hint howto do it better :wink: the cron as last job … i tried but didnt really work out.

currently i use tail -f /dev/null

#!/bin/bash

FILE=/scripts/guide2go.sh

if [ -f “$FILE” ]; then
echo “$FILE exist”
else
echo “$FILE does not exist”
mv /guide2go.sh /scripts/guide2go.sh
chmod +x /scripts/guide2go.sh
chmod 777 /scripts/guide2go.sh
fi

printf ‘50 03 * * * /scripts/guide2go.sh’ > /etc/crontabs/root

tail -f /dev/null

exit

what errors are you getting?

it always quitted when i used

crond

after some research i found

crond -l 2 -f

i hope thats correct then :wink:

Terpz actualy propses a universal and predictable solution to handle the issue.

Please consider the next senteces as FYI:

There are differences in how bind and named volumes treat the original content of the target folder.
– bind: the content of the source folder will be mounted into the target folder and its original becomes invisible to the container. A bind neither creates nor requires a volume.

– named volume: the content of the orignal target folder is copied into the volume. It needs to be declared in a docker-compose.yml or created from the cli before its uage. Named volumes can be bind (of local folders), nfs-shares, cifs-shares or whatever the volume plugins you install allow.

Espacly the named volume solution is often a surprise for users… stick with what Terpz proposed.

Thank you for the Information.

thanks again for pointing into the correct direction,
got my docker working as it should.

1 Like