Reputation: 127
I am trying to find a solution to make a process/service running on host available inside a container. Example a host is running Apache2 service which has 4 containers running. Just the way using VOLUMNES we can link the host's directory to container, is there any way to fork a reference of the Apache2 service from host to container?
Upvotes: 1
Views: 902
Reputation: 4706
From the Docker official doc:
echo "hello from host!" > ./hello
python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
docker run \
--add-host host.docker.internal:host-gateway \
curlimages/curl -s host.docker.internal:8000/hello
hello from host!
Upvotes: 0
Reputation: 25597
You ask in general terms which makes this hard to answer, since different services communicate with their clients in different ways.
But let's take a service that communicates over http like Apache. You have that running on the host at port 8080. Then you can add the host with the option --addhost=host.docker.internal:host-gateway
on the docker run
command and you'll then be able to reach the host at host.docker.internal
from inside the container.
As an example, you can use a curl image and reach the Apache server from inside the container like this
docker run --rm --add-host=host.docker.internal:host-gateway curlimages/curl http://host.docker.internal:8080/
Note the URL at the end (http://host.docker.internal:8080/
) which will hit port 8080 on the host.
Upvotes: 1