Remote access to webserver in docker container

前端 未结 4 640
有刺的猬
有刺的猬 2020-12-28 23:44

I\'ve started using docker for dev, with the following setup:

  • Host machine - ubuntu server.
  • Docker container - webapp w/ tomcat server (using https).<
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 00:34

    If your container was built with a Dockerfile that has an EXPOSE statement, e.g. EXPOSE 443, then you can start the container with the -P option (as in "publish" or "public"). The port will be made available to connections from remote machines:

    $ docker run -d -P mywebservice
    

    If you didn't use a Dockerfile, or if it didn't have an EXPOSE statement (it should!), then you can also do an explicit port mapping:

    $ docker run -d -p 80 mywebservice
    

    In both cases, the result will be a publicly-accessible port:

    $ docker ps
    9bcb… mywebservice:latest … 0.0.0.0:49153->80/tcp …
    

    Last but not least, you can force the port number if you need to:

    $ docker run -d -p 8442:80 mywebservice
    

    In that case, connecting to your Docker host IP address on port 8442 will reach the container.

提交回复
热议问题