Docker change published ports on live container

I’d like to change the published ports on a live container for example

docker run -p 80:80 --name nginx_live nginx

And then later on, change that to another port, example -p 8080:80

  • Is it possible to install only the docker cli and not the daemon
  • DOCKER_TLS_VERIFY, DOCKER_HOST, and DOCKER_CERT_PATH on Ubuntu
  • Starting container as a non-root user vs starting as root and then downgrade to non-root
  • Publisher Public key for docker notary
  • Apache and passenger behave differently on Docker mac vs ubuntu
  • Running Docker in PyCharm using Windows and virtualenv (Tensorflow)
  • how to configure docker container to run /usr/sbin/sshd upon startup
  • Cannot access port on host mapped to docker container port
  • Does a restart in a Dockerfile make sense?
  • How to launch AVD while keep running docker
  • How to run docker-compose in Azure Container Service and deploy to agent rather than master?
  • Docker-swarm overlay network is not working for containers in different hosts
  • 2 Solutions collect form web for “Docker change published ports on live container”

    Docker does not have a mechanism for changing the published ports of a container once it has started. When you publish a port, two things happen:

    • Docker creates iptables rules in the nat table that redirect traffic to the “public” port to the container.
    • Docker starts a proxy service listening on that port to handle locally generated traffic.

    While you could in theory manually update the firewall rules to make the service available at a new port, you would not be able to unbind the Docker proxy and would thus be unable to start any new services using that “public” port.

    Your best course of action is simply to delete the container and redeploy it, or rely on some sort of front-end proxy to handle the redirect rather than using Docker’s port publishing mechanism.

    That’s not a Docker feature.

    But it’s easy to add another layer of indirection: expose one container-port on your host and then run an instance of nginx or a firewall FORWARD rule that maps whatever local ports you want onto that docker-shared port.

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