How to assign as static port to a container?

后端 未结 2 625
春和景丽
春和景丽 2020-12-10 03:50

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

相关标签:
2条回答
  • 2020-12-10 04:26

    When you start docker, you can use the '-p' parameter.

    docker run -p 80 yourimage apache2 will do what you currently have.

    Now, you can specify ':' to make this port static:

    docker run -p :80 -p :443 yourimage apache2

    If you are using a Dockerfile with the EXPOSE instruction, it is the same thing :)

    0 讨论(0)
  • 2020-12-10 04:42

    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.

    0 讨论(0)
提交回复
热议问题