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)

  • docker daemon not connecting
  • Docker Nginx + Node: address already in use
  • Running Docker pull command in Dockerfile
  • Can't connect to Windows 10 Docker mysql
  • Docker deployment workflow of new application release without loosing database state?
  • side effect of --rm: when exit a container build with docker run --rm -v /myvol, also the volume is removed
  • How do I debug docker port mapping?
  • IBM-Bluemix: image reported by IBM Containers compressed - smaller than local Docker engine
  • I installed a docker on osx, now bundler is horrifically slow
  • php 5.6 elasticache client on alpine 3.4
  • How to ingest files in a docker container from another machine?
  • how to start docker service with a specific port in linux (ubuntu/centos)
  • 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.