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 
2
  • Problem is little unclear. You want to docker run in background? Commented Oct 30, 2016 at 7: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. Commented Oct 30, 2016 at 7:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.