Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

docker - How to assign as static port to a container?

I want to assign a container a port, so that it gets the same port after every restart of the container.

Example: I have a container, which has an Apache in it. The Apache runs on port 80 inside the container. Now, after starting the container, docker assigns a host port to the container port, for example: 49154 -> 80. But the host port changes after restart, depending on the number of running containers. I tried to specify the port in the config.json file of the container, but it gets overwritten.

Is it possible to specify the host port manually?

Thanks in advance and best regards, Chris

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Per the docker.io documentation: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

$ sudo docker run -p 80:80 <image> <cmd>

Default port redirects can be built into a container with the EXPOSE build command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...