I have a script run_test.sh
. I need to run a script not in a container. But how can i run it if the script file is in the container? Also when i call this script it starts this container.
I have windows
and WSL ubuntu 22.04
Asked
Active
Viewed 197 times
0

Nick ODell
- 15,465
- 3
- 32
- 66

visiwat303
- 11
- 3
-
A container can't usually run commands on the host system. The linked question has several workarounds, but they're quite involved. If you have the image's original source, it might be easier to just run the script without involving Docker at all. – David Maze Feb 08 '23 at 11:23
1 Answers
0
If I understand you correctly, you have a Docker image that contains a script that you want to run directly on the host.
To do that, let's create a Dockerfile that creates an image with a script called script.sh
like this
FROM debian
WORKDIR /app
RUN echo '#!/bin/bash' > script.sh && \
echo 'echo ''Hello''' >> script.sh
You can the run the image, cat
the script to stdout and pipe it into bash, like this
docker build -t test .
docker run --rm test cat script.sh | bash -
That will run the script on the host and print 'Hello'.

Hans Kilian
- 18,948
- 1
- 26
- 35