Search code examples
dockerdocker-volume

Is it possible run multiple setup scripts of subdirectories on docker container startup


I would like to run an oracle docker container using docker-compose. In my docker-compose.yml file i mount the docker volume as volumes: - /host/folder:/opt/oracle/scripts/setup

Actually the /host/folder has multiple subdirectories containing some setup scripts which i want them to be executed when i do docker-compose up. Would runScripts.sh in container consider the subdirectories too ?


Solution

  • No. docker-compose does not consider your subdirectories for that.

    You can run a specific bash script according to your requirements in which you can execute the specific scripts.

    Your docker-compose.yml will look like following:

    version: "3"
    
    services:
      setup:
        image: ubuntu:latest
        volumes:
          - ./startup-script.sh:/root/startup-script.sh
          - /host/folder:/opt/oracle/scripts/setup
        entrypoint: "/root/startup-script.sh"
        stdin_open: true
        tty: true
    
    

    And startup-script.sh will look like following:

    #!/bin/bash
    
    bash /directory1/script.sh
    bash /directory2/script.sh
    bash /directory3/script.sh
    bash /directory4/script.sh
    
    /bin/bash
    exec "$@"
    
    

    So, when docker container gets up, startup-script.sh will be executed and it will then execute all of your other required scripts.

    Note: If your container is not of ubuntu image and supports sh instead of bash, then you can replace /bin/bash with bin/sh within your docker-compose.yml and startup-script.sh