My Dockerfile have a script to run on ENTRYPOINT. The container is planned to run with a volume mount where my code resides, and it needs to run couple of commands once the container is up with volume mount.
But from errors I get while running container, I believe Docker volume mount happens after the ENTRYPOINT script.
I sure can run the commands with docker exec options once container is up. But that makes it more lines of running commands. Is there any work-around, even by using docker-compose?
Dockerfile :
FROM my-container
WORKDIR /my-mount-dir
ADD startup-script.sh /root/startup-script.sh
ENTRYPOINT ["/root/startup-script.sh"]
Docker Run :
docker run -itd -v /home/user/directory:/my-mount-dir build-container
Note : startup-script.sh includes commands supposed to run on the mounted directory files.
I'm not sure if this is the solution you want but I've been using this run command which uses cat command to supply my script.sh
to the container:
docker run -it --name=some_name --rm \
-v "host/path:/path/inside/container" \
image_name \
/bin/bash -c "$(cat ./script.sh)"
In this case the script runs after the mount is complete. I am sure of this as I've used the files from the mounted volumes in the script.
I have seen that in some of my scripts and it looks like file system cache problem to me... I use the following hack in my docker file and it works like a charm:
ENTRYPOINT ls /my-mount-dir && /root/startup-script.sh
But then you cannot use the list form for the ENTRYPOINT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With