Docker run script in host on docker layout up

Thank you for watching this question.

So my question is about best practices for running the script in the docker-compose up directive.

I am currently sharing volumes between the host and container so that script changes are displayed for both the host and the container. Similar to viewing a polling script for changes to a configuration file.

The script must act on the host when changes are made according to predefined rules.

So my question is:

How can I run this script in the docker-compose up directive or even from the docker file for this service, so that whenever the container goes up, the β€œobserver” can detect any changes made and write.

The container in question will always work on the debian / ubuntu OS and should be architecture independent, that is, it should also work on ARM.

Thank you in advance

I would also like to know why the question was suppressed only because some people do not understand this.

I want to run the script on the host, not inside the container. I need the host to change its network interface configurations to easily adapt any environment. HOST needs to be changed. I repeat. It should be a user and easily edited on a web interface running inside CONTAINER to adapt to new environments.

I am currently doing this with a script running on a crontab based host. I just want to know the best practices and examples of how to run a script in a HOST from an INSIDE CONTAINER, so deployment can be simple for the installation operator to just run docker build.

thanks

+3
source share
3 answers

I just want to learn the best practices and examples of how to run a script in a HOST from an INSIDE CONTAINER, so for the install statement it can be as simple as just running docker-compose up

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

  • The host should start a small server (select the port and specify the type of request you should expect)
  • The container, after its launch, should send this request to this server
  • Then the host should run script / trigger the desired changes.

This can have serious security problems, so use them at your own risk.

+1
source

The script should run continuously in the foreground.

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

When using cli, use docker run -d IMAGE SCRIPT

0
source

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

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

I'm not sure if scripting on the host from the container is possible, but if possible, this is a serious security flaw. Containers must be insulated in order to use containers.

0
source

Source: https://habr.com/ru/post/1265729/


All Articles