Good day!
The
docker exec command runs the command in the namespace of the container. One namespace is the file system. Therefore, unless the command is part of the image, directly written to the container, or you have already installed the host volume to map the host directory to the container, you will not be able to execute it. The host volume may be as follows:
docker run -v /host/scripts:/container/scripts -n your_container $your_image
docker exec -it your_container /container/scripts/test.sh
The host volume can be the same path on the host and container.
If the shell script is used, the I/O redirection can be used. For example:
docker exec -i $container_id /bin/bash
However, note that because the script content has replaced the terminal with a standard input, you cannot perform an interactive operation in this way. This is valid because the shell inside the container handles only the commands from stdin.