简体   繁体   中英

Changing dockers port in docker-compose has no effect on containerized java app

Assuming, that this is true:

 service port:container port
         8081:8080

  • The application starts on port 8080, according to its startup logs (see below). Now I changed the ports to 8083:8083 , expecting that the service port and container port both will be 8083.

  • After changing the port in the docker compose I redeploy it using docker stack deploy -c docker-compose.yml somename

  • When I do another docker ps I see that the container is still running on port 8080.


Containerized java app startup logs:

2019-02-24 17:06:00.665  INFO 1 --- [           main] c.l.a.ArticleServiceApplication          : Starting ArticleServiceApplication v0.0.1-SNAPSHOT on 42ccc7a1554c with PID 1 (/articleservice-0.0.1-SNAPSHOT.jar started by root in /)
2019-02-24 17:06:00.748  INFO 1 --- [           main] c.l.a.ArticleServiceApplication          : No active profile set, falling back to default profiles: default
2019-02-24 17:06:30.505  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-02-24 17:06:32.601  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1643ms. Found 1 repository interfaces.
2019-02-24 17:06:48.016  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$33ba8b8e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-02-24 17:07:01.769  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)

docker-compose file:

version: "3"
services:
  articleservice:
    image: elps/articleservice:1.1.0.5
    deploy:
      replicas: 2
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.role == manager
    ports:
      - "8081:8080"
...

Internally, during startup time, your Java app needs to be told that it should start up on port 8083 - simply putting it in the port forward config won't do the trick since the java application startup is isolated from how you want to configure your containers to get started up.

Usually, for most OSS applications, there should be some environment variable that you can set to make the Java application start up on a certain host/port (inside the container network interface, which is different from that on the host).

After that, if you have 8080:8083 , that means that you are wanting to forward the container's port 8083 to your host system's port 8080.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM