title: Docker swarm with a custom network
body: <p>I'm trying to work out how to properly use swarm mode in Docker. First I tried running containers on my 2 workers and manager machine without specifying a custom network (so I'm using the default ingress overlay network). However, If I use the ingress network, for some reason I cannot resolve <code>tasks.myservice</code>.</p>
  
  <p>So I tried configuring a custom network like this:</p>
  
  <pre><code>docker network create -d overlay elasticnet
  </code></pre>
  
  <p>So now, when I <code>bash</code> into one of the containers, I can successfully resolve <code>tasks.myservice</code> but I can no longer access the port I've defined in my service creation under <code>--publish</code> externally (which I could when I used the ingress network).</p>
  
  <p>Is there any way of either:</p>
  
  <ol>
  <li><p>Use the ingress network and be able to resolve <code>tasks.myservice</code> or any other DNS record that will direct to all of my service containers?</p></li>
  <li><p>Or, use a custom network, but <code>--publish</code> ports correctly so I could access them externally?</p></li>
  </ol>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is how I create my service,</p>
  
  <p>Without a custom network:</p>
  
  <pre><code>docker service create --replicas 3 --label elasticsearch --endpoint-mode vip --name elastic -e ES_HOSTS="tasks.elastic" --publish 9200:9200 --mount type=bind,source=/tmp/es,destination=/usr/share/elasticsearch/config  --update-delay 10s   es:latest
  </code></pre>
  
  <p>With a custom network:</p>
  
  <pre><code>docker service create --replicas 3 --network elasticnet --label elasticsearch --endpoint-mode vip --name elastic -e ES_HOSTS="tasks.elastic" --publish 9200:9200 --mount type=bind,source=/tmp/es,destination=/usr/share/elasticsearch/config  --update-delay 10s   es:latest
  </code></pre>