matching service names in docker-compose and those of kubenetes

3/5/2018

I have a configuration in Google Cloud kubernetes that I would like to emulate with docker-compose for local development. My problem is that docker-compose creates a service name with the name of the folder (purplecloud) plus underscore at the front and underscore plus "1" at the end while kubernetes does not. Further, kubenetes does not let me use service names with "_". This causes me the extra step of modifying my nginx config that routes to this micro-service and other microservices with the same naming problem.

Is there a way to name the service in docker-compose to be same as kubernetes?

My Google Cloud yaml includes

apiVersion: v1
kind: Service
metadata:
  name: account-service # matches name in nginx.conf for rule "location /account/" ie  http://account-service:80/
spec:
  ports:
  - port: 80
    targetPort: 80
  type: NodePort 
  selector:
    app: account-pod 

I have a nginx pod that needs to route to the above account micro-service. Nginx can route to this service using

http://account-service:80/

My docker-compose yaml includes

version: '3.1' # must specify or else version 1 will be used

services: 

  account: # DNS name is http://purplecloud_account_1:80/;
    build: 
        context: ./account
        dockerfile: account.Dockerfile
    image: account_get_jwt
    ports:
      - '4001:80' 
      - '42126:42126' # chrome debuger
    environment:
      - PORT=80

I have a nginx pod that needs to route to the above account micro-service. Nginx can route to this service using

http://purplecloud_account_1:80/

So I need to swap out the nginx config when I go between docker-compose and kubernetes. Is there a way to change the name of the service in docker-compose to be same as kubernetes?

-- grabbag
docker
docker-compose
kubernetes
nginx

0 Answers