Docker swarm and service discovery

I’m moving away from docker-compose files to using docker swarm but I just can’t figure this out.

I have two services – a nginx proxy, and a website both running just fine in docker swarm (which has three nodes)

  • Jenkins triggers jobs without git changes
  • Docker: Is it possible to share data between 2 containers without a volume?
  • Why docker uses port numbers from 32768-65535?
  • Chronos framework connect and disconnect from Mesos
  • How can I fix 'No space left on device' error in Docker?
  • How to view logs for a docker image?
  • The issue I’ve got is I need to configure nginx to proxy_pass to the backend website. Currently the only way I can get this to work is by specifying an ip address of one of the nodes.

    My services are created as follows:


    docker service create --mount type=bind,source=/../nginx.conf,target=/etc/nginx/conf.d/default.conf \
    -p 443:443 \
    --name nginx \
    nginx

    and


    docker service create --name ynab \
    -p 5000:5000 \
    --replicas 2 \
    scottrobertson/fintech-to-ynab

    I’ve tried using the service name but that just doesn’t work.

    Really I don’t think I should have to even expose the ynab service ports (at least that would work when I used docker-compose)

    In one of the nginx containers I have tried the following:

    root@5fabc5611264:/# curl http://ynab:5000/ping
    curl: (6) Could not resolve host: ynab
    root@5fabc5611264:/# curl http://nginx:5000/ping
    curl: (6) Could not resolve host: nginx
    root@5fabc5611264:/# curl http://127.0.0.1:5000/ping
    curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
    root@5fabc5611264:/# curl http://localhost:5000/ping
    curl: (7) Failed to connect to localhost port 5000: Connection refused

    Using the process list I tried connecting to the running instances id, and name:

    root@5fabc5611264:/# curl http://ynab.1:5000/ping
    curl: (6) Could not resolve host: ynab.1
    root@5fabc5611264:/# curl http://pj0ekc6i7n0v:5000/ping
    curl: (6) Could not resolve host: pj0ekc6i7n0v

    But I can only get it to work if I use the nodes public ip addresses:

    root@5fabc5611264:/# curl http://192.168.1.52:5000/ping
    pong
    root@5fabc5611264:/# curl http://192.168.1.53:5000/ping
    pong
    root@5fabc5611264:/# curl http://192.168.1.51:5000/ping
    pong

    I really don’t want to use a public ip in case that node goes down. I’m sure I must just be doing something wrong!

  • How Can I Link a Apache and Tomcat Containers Over AJP?
  • GitLab CI ssh registry login
  • Swift SQLClient connect to my local mssql database gives me error O Linker Error “_iconv”
  • Is there any way to access a docker (nginx) container via a local url like http://mydomain.dev?
  • Docker container bridged interface to assign IP address
  • Add User to Docker Container
  • One Solution collect form web for “Docker swarm and service discovery”

    The services need to be connected to the same network for this to work.

    $ docker network create -d overlay fake-internet-points
    $ docker service create --name service_one --network fake-internet-points [...]
    $ docker service create --name service_two --network fake-internet-points [...] 
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.