1

Not for production. I was able to run nginx in a container like so:

# docker run --rm -itp 4000:80 nginx
# curl localhost:4000
<outputs welcome page>

But with docker compose it doesn't work:

docker-compose.yml:

version: '3'

services:
  nginx:
    image: nginx:stable
    ports:
      - "4001:80"

Then,

# docker stack deploy -c docker-compose.yml s1
# curl localhost:4001
<hangs>

But it works this way:

# curl DOCKER0_IP:4001

or

# curl DOCKER_GWBRIDGE:4001

I'm running Arch Linux.

docker stack ls:

NAME                SERVICES            ORCHESTRATOR
s1                  1                   Swarm

docker stack ps s1:

ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
s9en6oyoj338        s1_nginx.1          nginx:stable        yuri                Running             Running 13 seconds ago

pacman -Qs docker | sed 'n;d':

local/docker 1:18.09.0-2

docker service ls:

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
710d1lrq7phh        s1_nginx            replicated          1/1                 nginx:stable        *:4001->80/tcp
x-yuri
  • 16,722
  • 15
  • 114
  • 161
  • @Siyu I believe I'm running the latest version, see `pacman` output in the question. Can't you reproduce? What version are *you* running? – x-yuri Nov 22 '18 at 16:04
  • right, I meant to ask the output of `docker service ls`. Can't reproduce, same version – Siyu Nov 22 '18 at 16:06
  • @Siyu It works via `docker0` and `docker_gwbridge` interfaces. I guess your OS makes `docker0` automatically available. What's your OS? Can you show `iptables-save` output? – x-yuri Nov 22 '18 at 16:30
  • ubuntu 18.04. it shows lots of -A Forward and post routing – Siyu Nov 22 '18 at 16:52
  • Any update on this? I have landed into this exact problem on Arch Linux – Gagan T K Oct 27 '20 at 16:03
  • 1
    @GaganTK The update is probably as follows. You're not supposed to run Docker Swarm locally. Use docker-compose instead. But if you do (use Docker Swarm), it won't be accessible via `localhost`. – x-yuri Oct 28 '20 at 07:00

0 Answers0