1
  1. Main script
    1. copy a shell script to Docker a container
    2. docker exec -it containerid /bin/bash to login to the container
    3. exec sub shell script
  2. Sub shell
    1. executing docker commands.

The sub shell script is working fine from the container, but is unable to exit the container even after we use the exit command. This makes it impossible to return to the main shell script after the subshell has executed.

Steps performed:

  1. tried to exit the command in and out the subshell but the container is not exiting.
  2. tried using docker exec -i containerid /bin/bash

Mainscript

#!/bin/bash
# variable declaration
ssh to host user <<EOF
docker copy subshell to container
docker exec -it containerid /bin/bash
exec subshell.sh
exit
EOF

Subshell

#!/bin/bash
# variable declaration
# executing few docker commands and storing the output in files
exit # (expecting to come out of the container which is not working)
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
  • `docker run -d --name my_container containerid tail -f /dev/null` is the _"usual"_ way to keep a container alive. Then just `docker kill my_container` to stop it. – β.εηοιτ.βε Apr 29 '22 at 07:04
  • And if it is running already and you are running docker commands in the sub shell, then there is just no need to run `docker exec -it containerid /bin/bash` at all. – β.εηοιτ.βε Apr 29 '22 at 07:06
  • 1
    Note that the `exit` command in your HERE document is redundant, as it can never be reached. – user1934428 Apr 29 '22 at 07:12
  • Container is in running state already. we do not want to stop the container instead we need to run few shell commands like jps, jstack and come out of the sub shell. Container should be running. – kallingaleamrutha Apr 29 '22 at 07:15
  • exit command with/without we have tried with no luck – kallingaleamrutha Apr 29 '22 at 09:50

0 Answers0