简体   繁体   中英

Docker swarm service port not exposed

I cannot connect to a service running on docker swarm. The swarm seems ok because I can connect to other containers running on it. I running the service with docker stack deploy -c docker-compose.yaml nifi and the docker compose file is:

version: "3.3"
services:
  registry:
    image: apache/nifi-registry:0.3.0
    ports:
      - "18080:18080"
  deploy:
    replicas: 1
    restart_policy:
      condition: on-failure

When I run this without the swarm ie docker-compose -f docker-compose.yaml up it works fine and I can browse to it. When I run it with docker stack deploy -c docker-compose.yaml nifi I see the same log entries for the service but cannot browse to it.

$ docker version

Client:
  Version:      18.03.1-ce
  API version:  1.37
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Wed Jun 20 21:43:51 2018
  OS/Arch:      linux/amd64
  Experimental: false
  Orchestrator: swarm

Server:
  Engine:
    Version:      18.03.1-ce
    API version:  1.37 (minimum version 1.12)
    Go version:   go1.9.5
    Git commit:   9ee9f40
    Built:        Wed Jun 20 21:42:00 2018
    OS/Arch:      linux/amd64
    Experimental: false

Does anyone have suggestions for fixing or troubleshooting this?

In swarm

ports:
  - "18080:18080"

will expose port on all swarm nodes and in case of use of the port on some of the nodes by another service you can have problems

you can expose port only on host with container

services:
  registry:
    ports:
      - target: 18080
        published: 18080
        mode: host

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