Docker run script in host on docker-compose up

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.

  • Docker push failed due to “access denied… private image”
  • Automatic Docker stop after running in CentOS [closed]
  • docker-compose.yml vs docker-stack.yml what difference?
  • How to connect to a docker server on the network set-up with Hyper-V
  • XDebug could not open the remote debug file '/var/log/xdebug.log' while reading response header from upstream
  • installation of nodejs returned a non-zero code: 1 with docker build
  • Currently i’m sharing a volume between host and container to allow for the script changes to be visible to both host and container.
    Similar to a watching script polling for changes on configuration file.

    The script has to act on host on changes according to predefined rules.

    So my question is:

    How could I start this script on a docker-compose up directive or even from the dockerfile of the service, so that whenever the container goes up the “watcher” can find any changes being made and writing to.

    The container in question will always run over a debian / ubuntu OS and should be architecture independent, meaning it should be able to run on ARM as well.

    Thanks in advance

    I would like to know as well, why was the question downvoted just because some people don’t understand it.

    I wish to run a script on the Host, not inside the container.. I need the Host to change its network interface configurations to easily adapt any environment The HOST needs to change I repeat.. This should be seamless to the user, and easily editable on a Web interface running Inside a CONTAINER to adapt to new environments.

    I currently do this with a script running on the host based on crontab. 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.

    Thank you

  • Gitlab run docker inside docker
  • Issues with Running Flask and SQLAlchemy app through Docker
  • Why does Django not find the admin/base_site.html file when I dockerize the app?
  • How to know the file from command “docker change” is regular file or directory
  • Docker & PM2: String based CMD with environment variables
  • Unable to Launch Node.js Application Inside Built Docker Container
  • 3 Solutions collect form web for “Docker run script in host on docker-compose up”

    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.

    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

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.