Docker Community Forums

Share and learn in the Docker community.

Docker deploy with named services

docker

(Yashgt) #1

Hi,

I have defined a client and a server as docker services and am trying to deploy them such that the client can connect to the server using the server’s name.
The stack is named e1. I notice that the containers get names with a prefix as e1. Due to this, the client cannot identify the server as my_server, but has to connect using the name e1_my_server. The client code is fixed and it assume that the server is named my_server.

How do I ensure that the client can reach the server using the service name as defined in the compose file? My real intention is to spawn multiple such stacks which are independent of each other but with services communicating with each other using names.

I use Docker version 1.13.0-rc1, build 75fd88b
This is in swarm mode.

[admin@gol05854 compose]$ cat docker-compose.yml
version: '3’
services:
my_client_1:
image: yashgt/client
build: …/client
#restart: on-failure:3
volumes:
- serverlog:/log
depends_on:
- my_server
labels:
- "constraint:node==gol05854"
networks:
- mynet
my_server:
image: yashgt/proc1
#image: gophernet/netcat
#command: -v -l -p 5000
expose:
- "5000"
build: …/proc1
#restart: on-failure:3
volumes:
- serverlog:/log
labels:
- "constraint:node==gol05854"
networks:
- mynet
volumes:
serverlog:
driver: local
networks:
mynet:
driver: overlay

[admin@gol05854 compose]$ ~/docker/docker deploy --compose-file docker-compose.yml e1
Ignoring unsupported options: build

Ignoring deprecated options:

expose: Exposing ports is unnecessary - services on the same network can access each other’s containers on any port.

Updating service e1_my_server (id: ga6qk8h46xhj7553asqx49a2r)
Updating service e1_my_client_1 (id: aef0z25w8t601o4c42beziiqj)

[admin@gol05854 compose]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a05dadf60bfd yashgt/proc1:latest “/bin/sh -c ./serv…” 39 minutes ago Up 38 minutes e1_my_server.1.9vo53zptr4b3bnsci3u86foq2
cb7a50745cce yashgt/client:latest “/bin/sh -c ./clie…” 39 minutes ago Up 38 minutes e1_my_client_1.1.hzi0fz8br8wtffhn8ctxrls17