0

Below is a loop I am implementing where a docker image is created and run with the parameters from the loop. I am using jq to iterate a json file. Below is the snippet:

jq -c -r '.triggers.endpoint[]' config.json | while read i; 
do
    echo "Running container for ${i}"
    export TEMPLATE_PATH=$1
    export BUCKET="something"
    export UPPERCASE_ENDPOINT=${i^^}
    export NAME="${APPLICATION}_${UPPERCASE_ENDPOINT}"
    export PREFIX="something/${i}"
    docker run -i -a stdin -a stdout -a stderr --rm \
            -v "$PWD":/tmp \
            -w /tmp \
            -e SLICE \
            -e STAGE \
            -e PREFIX \
            -e AWS_REGION \
            -e NAME \
            -e BUCKET \
            $CONTAINER --verbose $TEMPLATE_PATH
done

The issue I am facing is that the docker run is ending my bash script, so the loop works perfectly for the first iteration but ends there and does not finish the loop. Running this in detached mode does not work.

Does anyone have any suggestions in how I can debug and figure this issue out?

  • It looks like your container is reading from stdin and probably consuming all the output from `jq`. Why are you attaching to stdin (with `-a stdin`)? – larsks Oct 29 '21 at 02:21
  • @larsks I don't actually need `-a stdin`, should have removed it from the snippet above. The container definitely reads from `stdin`. How can I get around what you have mentioned? – iammr10k Oct 29 '21 at 02:24
  • Just so it is clear - it doesn't need the `-a stdin` and it should have been removed OR the container definitely read from `stdin` (as in needs it), it is either one or another :) – jabbson Oct 29 '21 at 02:33
  • @jabbson to be clear, it does not need `-a stdin` and should have been removed. The docker container can execute successfully without. Sorry, am very new to docker and bash! – iammr10k Oct 29 '21 at 02:37
  • Without the `-a` flags, the loop should be able to start spinning containers, but one by one. Without `-a` you can definitely throw that `-d` to start them all together, alternatively you can add the `&` at the end of the docker command to start them in the background (as in without blocking). – jabbson Oct 29 '21 at 02:41
  • @jabbson if i want to then pass input/environment variables to the container, would i need to use `docker attach` with `-itd`? – iammr10k Oct 29 '21 at 03:00

0 Answers0