docker-composedocker-entrypoint

docker-compose entrypoint with multiple or multiline commands


How to run docker-compose entrypoint configuration option with multiple or multiline bash commands

commands:

yarn install
yarn build
sleep infinity


Solution

  • I figured out how!

    Steps:

    1. In docker-compose.yml, say for service: gvhservice, add below lines of code
      gvhservice:
        entrypoint:
          - "/bin/sh"
          - -ecx
          - |
              yarn install
              yarn build
              sleep infinity
    
    1. optionally, add all these commands to a file say - entrypoint.sh

    Where in entrypoint.sh, add below lines of code:

    #!/bin/sh
    
    set -ex
    
    yarn install
    yarn build
    sleep infinity
    

    where in docker-compose.yml, add below lines of code:

      gvhservice:
        entrypoint: entrypoint.sh
    
    1. By using combination of a docker ENTRYPOINT instruction within the container and command instruction and operator | configuration option in docker-compose.yml (suitable for a variable number of commands to be passed during runtime)

    build you container with instruction: COPY entrypoint.sh . and

    where contents of entrypoint.sh is:

    #!/bin/sh
    
    set -ex
    
    exec "$@"
    

    where in docker-compose.yml, add below lines of code

      gvhservice:
        entrypoint: entrypoint.sh
        command:
          - "/bin/sh"
          - -ecx
          - |
              yarn install
              yarn build
              sleep infinity