'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.



Solution 1:[1]

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

Solution 2:[2]

The entrypoint script does run after the volume mount. I encountered a similar issue but it was actually due to using single quotes around the entrypoint instead of double quotes. Because of this, the container was falling back to using the default entrypoint of /bin/sh. As your question is already answered, I'm leaving this for others who end up here via Google.

This:

ENTRYPOINT ["entrypoint.sh"]

Not this:

ENTRYPOINT ['entrypoint.sh']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Blaa_Thor
Solution 2 S.Walsh