Omar Faroque Anik
Omar Faroque Anik

Reputation: 2609

All the process logs from container

I have a container, it starts with shell script.sh such as:

 FROM bash:4.4

 COPY script.sh /
 COPY process.sh /

 CMD ["bash", "/script.sh"]

Here is script.sh:

 #!/bin/sh

 sh process.sh &

 for i in {1..10000}
 do
     sleep 1
   echo "Looping ... number $i"
 done

It starts another process by running process.sh script.

Here is the process.sh script:

 #!/bin/sh
for i in {1..10}
 do
   sleep 1
   echo "I am from child process ... number $i"
 done

Now I want to see all the stdout message. If I go to the directory like /var/lib/docker/containers/container_sha: I see something like below:

I am from child process ... number {1..10}
Looping ... number 1
Looping ... number 2
Looping ... number 3
Looping ... number 4
Looping ... number 5
Looping ... number 6
.....

It is obvious that, I see only the script.sh output but not process.sh

Why is that? And how can i get all the logs?

Note: docker logs containerName does the same.

Upvotes: 0

Views: 321

Answers (1)

dan
dan

Reputation: 5231

{1..10} is bash syntax, and does not expand to anything in sh. So the loop runs once, with the word {1..10} (literally).

You can run process.sh with bash instead of sh

Or if you want/need sh, you could either:

Use a counter:

while c=$((c+1)); [ "$c" -le 10 ]; do

Use a program like seq (not POSIX):

for i in $(seq 10); do

Iterate arguments passed from bash like:

sh process.sh {1..10} &

and in process.sh:

for i do

Upvotes: 1

Related Questions