You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, as shown, the command will run in the foreground and the user will be unable to run the rest of the commands in the same terminal session. If the user presses ctrl-c to terminate python to be able to run the container, the example won't work since the web server isn't running.
My own solution was to run python3 in the background by adding & to the command. However then I needed to kill the web server after running the container. Getting the pid and killing python isn't very elegant. Hopefully you can come up with a better solution.
The text was updated successfully, but these errors were encountered:
Hm... yes, that's a good one; I know we tried to write up a minimal-as-possible example just to illustrate the concept, but indeed running things in the background can be slightly tricky, or at least to keep things "simple" as well as (where possible) working across platforms (mac, linux, windows).
I guess a "scrappy" workaround here could be to have the user open two separate shells; one to run the Python server and another one to run the docker commands to connect to it.
# Use the official Python image
FROM python:3.9-slim
WORKDIR /usr/src/app
# Copy the hello file into the image
COPY hello.txt .
# Start the HTTP server
CMD ["python3", "-m", "http.server", "8000"]
Right, but the host.docker.internal feature was added for users to have an option to connect to a services that's not running inside a container, so some service on the host. For the docker-compose case, the recommended approach would for the curl-client service to connect with the python-server service through the internal network (are least; "don't map ports that shouldn't be accessible publicly").
In the documentation at https://github.com/docker/cli/blob/master/docs/reference/commandline/container_run.md#add-host, a python3 web server is run to server the
hello
file.However, as shown, the command will run in the foreground and the user will be unable to run the rest of the commands in the same terminal session. If the user presses ctrl-c to terminate python to be able to run the container, the example won't work since the web server isn't running.
My own solution was to run python3 in the background by adding
&
to the command. However then I needed to kill the web server after running the container. Getting the pid and killing python isn't very elegant. Hopefully you can come up with a better solution.The text was updated successfully, but these errors were encountered: