jacobcan118
jacobcan118

Reputation: 9037

get command executed result from docker container

anyway for me to know when command is finished inside docker container? I have created a docker container and able to send command from my local into docker container by docker exec so far in my bash script I am using sleep to wait until "cd root: npm install" command finished inside docker container. If I do not have sleep, done is printed out right away after npm install is sent into docker container. How can I remove sleep so done is printed out only after npm install is finished inside docker container?

docker exec -d <docker container name> bash -c "cd root;npm install" sleep 100 echo "done"

Upvotes: 1

Views: 1446

Answers (3)

BMitch
BMitch

Reputation: 263637

Don't background the command if you want to keep it running in the foreground (the -d flag):

docker exec <docker container name> bash -c "cd root;npm install"
echo "done"

Upvotes: 1

ideam
ideam

Reputation: 345

If you omit the -d (detach) the docker exec will return only after completion (and not immediately), so no wait will be needed.

Upvotes: 0

Kubator
Kubator

Reputation: 1383

Run it as background process & and then wait for it:

docker exec -d <docker container name> bash -c "cd root;npm install" &
wait
echo "done"

Upvotes: 0

Related Questions