title: Deploy Replicas in specific ports and hostname
body: <p>I need to deploy a docker container in a swarm. I want to deploy 4 replica of the docker container. I want to set the port which each container will run and I need to know their hostname.</p>
  
  <p>What I would is to lunch 4 replicas.</p>
  
  <ul>
  <li>Replica 1 should listen to port 3001 and hostname slave1.</li>
  <li>Replica 2 should listen to port 3002 and hostname slave2.</li>
  <li>Replica 3 should listen to port 3003 and hostname slave3.</li>
  <li>Replica 4 should listen to port 3004 and hostname slave4.</li>
  </ul>
  
  <p>Each replica has the same Dockerfile (because the process which I want to run is the same). In the Dockerfile I expose all the 4 ports using the standard command:
  EXPOSE 3001 3002 3003 3004</p>
  
  <p>I tried this docker-compose file where I use 4 ports and deploy using "mode:replicated"</p>
  
  <pre><code>services:
    slave:
      image: "DOCKER_REPO_NAME"
      deploy:
        mode: replicated
        replicas: 4
        restart_policy: 
          condition: on-failure
      networks:
        - my_net
      ports:
        - "3001:3001"
        - "3002:3002"
        - "3003:3003"
        - "3004:3004"
  
  networks:
    my_net:
      external: true 
  </code></pre>
  
  <p>but it is not working as I would and as described above.</p>
  
  <p>Hope the description of the problem makes sense. Please let me know.</p>