docker bind socket to outside port

I’m using docker. Inside docker I have app that binds listening socket to ip of outside machine (ip of machine where I have docker running). is there any way I can make such listening socket work? that’s bound to outside ip address (192.168.1.2) and not docker’s eth0 (172.17.0.248)

  • Running a Bash Script from (on Docker Container B) from Docker Container A
  • Using MySQL with Spring boot docker image
  • Is there anyway to start rsyslogd without sudo access?
  • Issue while indexing data in solr in docker cluster setup
  • docker-compose up : Encountered errors while bringing up the project
  • Rancher CLI random host port mapping
  • MupX, graphicsmagick and env var
  • Is Docker complementary or competitive to Spring Boot / Dropwizard? [closed]
  • Docker database files: inside or outside the container?
  • How to set an environment variable in a running docker container
  • Expose host port for specific container interface
  • Mounting local directory into Docker container path that is not exposed as a VOLUME
  • 2 Solutions collect form web for “docker bind socket to outside port”

    When you run the container map the port to the external port you want to reach it on. docker run -p 80:80 myapp This will let you access the docker container at 192.168.1.2:80. The command format is -p {external port}:{internal app port}.

    For further clarification. To access any application inside a container you will want to expose the port, see this. Essentially you map a port from the container to the host o/s.

    Example: You have an application running on port 8080 in your container, but you want to access it with your host ip at port 8000. You would run your app like so docker run -p 8000:8080 myapp. This will expose port 8080 to your host o/s as port 8000 at which point you could reach it at {host ip}:8000.

    Okay fixed myself:
    add new ip via “ip addr add”, then make iptable rule to preroute incoming packets to that ip and thats all 🙂

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