1

I have script like below the "docker run" is started and it will open tty for executing its command according of docker file,it'll take around 5-6 hours to report an execution end sign,but meanwhile I need to let it do the job and move forward in shell script lines and get some pid and make condition with it. No my problem is that I can't execute "docker run" and then move from it to other lines of script. how can I do that without influencing "docker run" command.

    docker run --name=something -it --rm \
      --link=postgresql:postgresql \  
      --publish=80:80 \
      --env='something_PORT=80' \
      --env='NGINX_MAX_UPLOAD_SIZE=60m' \
      --volume=/srv/docker/something:/home/something/data \
      --volume=/srv/docker/something/rgloader:/home/something/rgloader \
      something:3.3 \
      app:backup:restore

#30 sec pass till process starts to unpack tar file.
    sleep 30

#Get PID of tar extraction process
    PID=`ps au | grep "tar -xf" | head -n 1 | awk '{print $2}'`
echo $PID

echo "tar file extraction is completed"

#wait until tar extraction process ends

while [ -e /proc/$PID ]
do
    echo $PID PID still running
    sleep 10
done
Ali_T
  • 27
  • 1
  • 1
  • 6
  • Problem is little unclear. You want to `docker run` in background? – Rao Oct 30 '16 at 07:02
  • I know if I use "-d" I can run docker in daemon mode,but I just want run docker and let it do its job and go to next line, bash will stop in that line and I want it move forward. – Ali_T Oct 30 '16 at 07:04

1 Answers1

0

I know if I use "-d" I can run docker in daemon mode,but I just want run docker and let it do its job and go to next line,

Then the simplest approach is to launch docker in background

docker run ... &
              ^^^

Note that the rest of your script won't see the processes launched by your docker container (like a tar) directly from the host.
See "Finding Docker container processes? from host point of view".
You will have to use docker top for that.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250