Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Change Port Binding

Tags:

docker

port

I'm running a container (let's call it old_container) with exposed port 80 and bind the port to the host interface on port 80 using the -p flag.

sudo docker run -p 80:80 -i -t < old-image-id >

In my production environment I want to switch now from the old_container to a new_container. So I want to shut down the old_container and start the new_container.

First I have to do some manual changes in the new_container. So I run it without the -p flag, as I cannot bind it to port 80 before I have done this changes.

sudo docker run -i -t < new-image-id >
#now I m doing my manual changes

When I'm finished with my changes I logout of the new_container. My plan was now to stop the old_container and bind the new_container to port 80. But the [start][1] command does not provide a port binding possibility.

So to come to my question: I'm looking to set the port binding for a stopped container, preferably without the workaround of creating a commit image of the new_container and running this image as another new container.

like image 472
Thomas Kremmel Avatar asked Jul 10 '14 13:07

Thomas Kremmel


1 Answers

  1. Make the changes to your new container and then stop both the old and new containers.
docker stop old_container new_container
  1. Create a new image from a container’s changes via the commit command like so:
docker commit new_container new_container_01
  1. Run the newly commited image:
docker run -p 80:80 -i -t new_container_01
  1. Cleanup your old, unused containers with the rm (remove) command:
docker rm old_container new_container
like image 160
JSON C11 Avatar answered Oct 05 '22 22:10

JSON C11