'Docker - Access to Host from Container [duplicate]

How can I access the host from the container? For example, I want to run a script on the host? are there any other ways to do this ? I thought only of SSH? are there other ways?



Solution 1:[1]

I ran this on Ubuntu 20.04, but should be more or less the same on all UNIX boxes... you will need to either mount a local dir to your container or use volume. That way, a particular local dir where you have your local script will be mounted to the folder within your container

Start your container using -v option

docker run -d -v /home/rootuser/LocalMcScriptFolder:/app/ContainerFolder YOURIMAGE

Go into your container, go to the folder and run the script

docker exec -it CONTAINERID bash
$cd ContainerFolder
$pwd
/app/ContainerFolder
$./test.sh

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman