How to convert a Spring-Boot web service into a Docker image?

前端 未结 2 1871
日久生厌
日久生厌 2021-01-07 01:32

I want to access my website from a Docker container but I can\'t. The steps I am trying to implement are as follows. After all the steps I can\'t access the http://loc

2条回答
  •  春和景丽
    2021-01-07 02:06

    When you run a Docker container, all the ports, which any application happen to listen on within it, are not published by default.

    In order to publish a port, you need to specify it while running the container using your image. For all the details on how to do it, you can check the "EXPOSE" section in the documentation of docker run command: https://docs.docker.com/engine/reference/run/

    Shortly speaking, you want to add another option while running your container:

    docker run --name mycontainer1 -p 8080:8080 myimage1
    

    I'm not sure if you wanted to achieve this by adding

    EXPOSE 8080
    

    in your Dockerfile. Actually, this does not mean that the port will be exposed when the image is used to run a container. As you might find in Dockerfile reference:

    The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.

提交回复
热议问题