Search code examples
linuxdockerdocker-composedockerfile

Docker ENTRYPOINT to run after Volume Mount


My Dockerfile has a script to run on ENTRYPOINT. The container is defined to run with a volume mount where my code resides, and it needs to run a set of commands once the container is up with a volume mount.

But the errors I get while running the container, make me believe that the Docker Volume Mount happens after the ENTRYPOINT script execution.

I can run the commands with docker exec once the container is up. But I can't use this option in my development workflow. Is there any work-around, maybe with 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 which is supposed to interact with files from the mounted directory.


Solution

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