docker-archive / classicswarm

Swarm Classic: a container clustering system. Not to be confused with Docker Swarm which is at https://github.com/docker/swarmkit
Apache License 2.0
5.75k stars 1.08k forks source link

Docker: Unable to ping another host from inside of container running in swarm #2966

Closed yogeshkathayat closed 4 years ago

yogeshkathayat commented 4 years ago

Environment:-

My compose file:-

version: "3.3"
networks:
  basic:
services:
  ping-test:
    image: yogeshkathayat/node-ping
    deploy:
      replicas: 1
    networks:
      - basic
    ports:
      - "3000:3000"

Issue:- I am not able to ping another host in the same local network from inside of the container, if I remove ports section from my Compose file then it is working perfectly. but I want to expose the port to the outside world.

Steps:-

  1. docker swarm init
  2. docker stack deploy --compose-file docker-compose.yml ping
  3. docker exec -it /bin/bash //go inside the container
  4. ping host in the same subnet or network
information-security commented 4 years ago

Please use this format for your ports and see if it solves your problem:

ports:
  - target: 3000
    published: 3000
    protocol: tcp
    mode: host
Ga11u commented 4 years ago

Did you tried to use tasks. as address ? https://docs.docker.com/network/overlay/#container-discovery

justincormack commented 4 years ago

This issue is for https://github.com/docker/swarmkit not the old standalone Swarm.