Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker ENTRYPOINT to run after volume mount

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.

like image 857
Vineeth Avatar asked Jul 11 '17 07:07

Vineeth


2 Answers

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.

like image 77
Ayushya Avatar answered Sep 18 '22 18:09

Ayushya


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

like image 21
Blaa_Thor Avatar answered Sep 19 '22 18:09

Blaa_Thor