Connect to a service in docker, run from an interactive shell

Suppose I have the following container:

docker run -i -t test/python3 /bin/bash

  • gulp watch seems to freeze in Docker
  • Running docker container at specific URL(s)
  • Does Kitematic 0.7.6 for Windows support Volumes?
  • how can i create a database on mysql docker service
  • Docker mounted volume not tracking nginx log files
  • Tomcat doesn't start in docker container because it can't create log files
  • and run the following in the shell:

    python3 -m http.server 8080

    How do I connect to this port from the host? Is this possible?

  • Volume mapped filebeat.yml permissions from Docker on a Windows host
  • Guacamole image in Docker getting blank login page
  • How do I connect my iPhone to my local docker container if they're both on the same network?
  • Docker - No route to host
  • Run Docker in daemon mode
  • Dockercloud service stops immediately after start
  • One Solution collect form web for “Connect to a service in docker, run from an interactive shell”

    You can connect directly to the container using its private IP. To discover it, in the host terminal you can run docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container_id>. The container_id can be obtained using docker ps once the container is running (also from the host). Once you have that ip you can access directly to it to the port you wish.

    Also you have the option to publish a container port to the host machine, thus you can access directly from you localmachine to localhost:8080, or from any other machine that has visibility with the host (to the adequate ip or hostname). To publish the port you have to use the option -p, as describer in the docker run prompt help:

    $ docker run --help
    -p, --publish=[]           Publish a container's port to the host
                                   format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort

    So in that case you could run docker run -i -t -p 8080:8080 test/python3 /bin/bash to, for example, publish the port 8080 of the container to the same number port of your local machine (you could choose any other not already in use in your host machine). Also may be you don’t need to run the container in a interactive way if you don’t need to perform any further action inside (or doing this using a script), and running directly the command you wish to execute: docker run -i -t -p 8080:8080 test/python3 python3 -m http.server 8080

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.