Docker run script in host on docker-compose up

前端 未结 3 1781
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-08 01:22

thank you for watching this question.

So my question relates to best practices on how to run a script on a docker-compose up directive.

Currently i\'m sharin

相关标签:
3条回答
  • 2021-01-08 01:36

    I just wish to know the best practices and examples of how to run a script on HOST from INSIDE a CONTAINER, so that the deploy can be as easy for the installing operator to just run docker-compose up

    It seems that there is no best practice that can be applied to your case. A workaround proposed here: How to run shell script on host from docker container? is to use a client/server trick.

    1. The host should run a small server (choose a port and specify a request type that you should be waiting for)
    2. The container, after it starts, should send this request to that server
    3. The host should then run the script / trigger the changes you want

    This is something that might have serious security issues, so use at your own risk.

    0 讨论(0)
  • 2021-01-08 01:48

    You can create an alias for docker-compose up. Put something like this in ~/.bash_aliases (in Ubuntu):

    alias up="docker-compose up; ~/your_script.sh"
    

    I'm not sure if running scripts on the host from a container is possible, but if it's possible, it's a severe security flaw. Containers should be isolated, that's the point of using containers.

    0 讨论(0)
  • 2021-01-08 01:55

    The script needs to run continuously in the foreground.

    In your Dockerfile use the CMD directive and define the script as the parameter.

    When using the cli, use docker run -d IMAGE SCRIPT

    0 讨论(0)
提交回复
热议问题