Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker restart a container will change the port mapping #8723

Closed
cc272309126 opened this issue Oct 23, 2014 · 9 comments
Closed

docker restart a container will change the port mapping #8723

cc272309126 opened this issue Oct 23, 2014 · 9 comments

Comments

@cc272309126
Copy link
Contributor

Hi,

after docker restart containerid,it will allocate a new port to the container,Is there a way hold the port for a container?or this is feature for docker?
reproduce steps
1,docker run -d -p 8080 imageid
2,docker restart containerid
3,compare the container the mapping port,you will found that the port is changed。

ps: on docker 1.2.0 after restart the container twice,the port will lost. but this issue can not be reproduced on docker docker-1.3.0-dev.
thanks

@cpuguy83
Copy link
Member

@cc272309126 1.3.0-dev would be master.
Did you try on 1.3.0, which was released last week?

@cc272309126
Copy link
Contributor Author

@cpuguy83 on 1.3.0 after restart the container the mapping port still changed, After I read the code, I found that restarting the container will allocate the mapping port again unless allocating a port for container manual. so I think maybe that's designing. and the mapping port lost has been fixed.

@hcguersoy
Copy link

I'm running into issues due to this behavior: I'm running a lot of containers on the hosts and sometimes (e.g. due to provisioning runs) the docker daemon is restarted. After this, all port mappings are different.
It would be nice if a container should preserve its used ports after an restart.

@cc272309126
Copy link
Contributor Author

@hcguersoy do you specify a host port mapping to a container port like "docker run -d -p 1234:1234 image command"?

@hcguersoy
Copy link

Hi,

sorry for my late answer...

No, I don't. But I would expect that a restarted container uses the same ports again.
Maybe I'm wrong ;-)

@gdm85
Copy link
Contributor

gdm85 commented Jan 20, 2015

I have also been hit by this bug, and it's a deployment blocker for me.

Although in production one will want to use fixed port mappings, there are scenarios (development, testing, staging) where you want containers to survive a daemon/host reboot and keep their port mapping, if not just to not destroy the work-flow of all involved people that are still using the containers.

@gdm85
Copy link
Contributor

gdm85 commented Jan 22, 2015

I have implemented stateful hostconfig save/restore in my docker-fw utility, feel free to give it a shot.

@jessfraz
Copy link
Contributor

closing as dup of #7158 which is why it gets another port

@jessfraz
Copy link
Contributor

also #9047 for reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants