Docker is written without the EXPOSE port, the best mirror in the operation of the container need to serve a port can be mapped to the host?

Scene: web container, when writing Docker only EXPOSE 80, the container has been running for some time, the development side need to open 8080 test questions:
1. Dockerfile no EXPOSE port, Docker run use-p mapping is valid? It is confirmed that the newly started container uses the -p parameter to bind the port, – the volume can mount the path, specify the EXPOSE in the Dockerfile, VOLUME is not required
2. Dockerfile no EXPOSE port, do not reopen the container, then you can add port? 2015-09-16 add comment share it

  • Weibo
  • Micro letter

Did not find the relevant results



    We agreed from:

    Well, the actual control of the container and host port mapping between the docker run-p parameters, Dockerfile is expressed in the EXPOSE impact is-P this parameter.
    and so,
    1, there is no statement to declare the use of the port -p is valid. But note that VOLUME and EXPOSE different, once the Dockerfile VOLUME, docker run time, docker will always host the directory mounted to the VOLUME statement of the directory and will VOLUME statement before the contents of the copy to the mount table of Contents.
    So then

      FROM ubuntu: latest 
    RUN echo "While building" >> / opt / file
    VOLUME / opt
    RUN rm / opt / file

    What happens with such a Dockerfile?

    2, Dockerfile regardless of whether there is no EXPOSE port, you need to add port mapping only restart container

    Heads up! This alert needs your attention, but it's not super important.