skip to Main Content

How can I trigger a shell script which is available in local folder in linux to run through an API which is containerized .

Through docker container I want to trigger the shell script which is available in local folder


services:

  webui:
    image: sample/webui
    container_name: webui
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 5000:5000
    volumes:
      - .:/usr/src/app:rw
    networks:
      - sampleApp

apis:
    image: sample/apis
    container_name: apis
    build:
      context: .
      dockerfile: apis/Dockerfile
    ports:
      - 8686:8686
    volumes:
      - ..:/data/sw_data:rw
    networks:
      - sampleApp


networks: {sampleApp: {}}

volumes:
  data:

2

Answers


  1. You are trying to defeat original purpose of container: to isolate an app in the container from the rest of the system to protect the underlying host from any effect caused by the application in the container. You can do this though:

    1. The container still have possibility to connect to port on the host. Listen on the host with simple server that would run the script.

    2. If you are happy with just running the script that resides in the local folder, simply mount the folder to the container and run it from there.

    Login or Signup to reply.
  2. You need to mount your script and then have to run it like below. Here I added two lines. One in volume and another is command. Volume will add script in docker and the command will run that script.

    apis:
    image: sample/apis
    container_name: apis
    build:
      context: .
      dockerfile: apis/Dockerfile
    ports:
      - 8686:8686
    command: ["/data/scripts/run.sh"]
    volumes:
      - ..:/data/sw_data:rw
      - <script-folder>:/data/scripts
    networks:
      - sampleApp
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search