Skip to content

Commit 0638fe2

Browse files
committed
docs: fix --add-host example to work in a single terminal session
The current example uses python3 -m http.server which runs in the foreground, blocking the terminal and preventing the user from running the subsequent docker command. The example only works if the user opens a second terminal. Replace with nc (netcat) which can be backgrounded with & disown, allowing the entire example to run in a single terminal session. This also removes the dependency on Python being installed on the host. Fixes #5558 Signed-off-by: Nanook <nanook@agentmail.to>
1 parent 950401c commit 0638fe2

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

docs/reference/commandline/container_run.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,8 @@ example runs an HTTP server that serves a file from host to container over the
12911291
`host.docker.internal` hostname, which resolves to the host's internal IP.
12921292

12931293
```console
1294-
$ echo "hello from host!" > ./hello
1295-
$ python3 -m http.server 8000
1296-
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
1297-
$ docker run \
1298-
--add-host host.docker.internal=host-gateway \
1299-
curlimages/curl -s host.docker.internal:8000/hello
1294+
$ printf 'HTTP/1.1 200 OK\r\n\r\nhello from host!\n' | nc -l 8000 & disown
1295+
$ docker run --add-host host.docker.internal=host-gateway curlimages/curl -s host.docker.internal:8000
13001296
hello from host!
13011297
```
13021298

0 commit comments

Comments
 (0)