I have ~4 microservices, a Keycloak and a RabbitMQ Server I want to deploy via Docker. Each microservice has to be able to speak to Keycloak, and some need to speak to RabbitMQ.
To keep it clean I wanted to create a docker-compose file for Keycloak, one for RabbitMQ, and one per microservice. Is this the right way to do it? (Each microservice has its own database.)
MS A, B, C, D need to be able to call Keycloak; MS C, D needs to be able to talk to RabbitMQ.
What is the best way to connect all the microservices with the Keycloak / RabbitMQ server(s)? Some of the microservices need to be able to talk to each other as well.
Docker includes support for networking containers through the use of network drivers. By default, Docker provides two network drivers for you, the bridge and the overlay drivers. You can also write a network driver plugin so that you can create your own drivers but that is an advanced task.
Can I still use Docker for development? Yes, you absolutely can, now and in the foreseeable future. You see, Docker doesn't run Docker-specific images; it runs OCI-compliant containers.
Conclusions. Docker containers are, by default, quite secure; especially if you run your processes as non-privileged users inside the container. You can add an extra layer of safety by enabling AppArmor, SELinux, GRSEC, or another appropriate hardening system.
You can do it via docker, but there are following things you need to consider,
If answer is dev or testing then yes you can use docker compose. It help you start all your containers from one place and you can have them configured in one file. You can have keycloak, rmq databases and services all set up on to same host via docker compose and they can talk to each other
If you want to do it for prod or prod like env, then we you can look into docker swarms. It is an incremental update from docker compose and let you deploy containers on multiple host.
If you have just four services, you can do with it, but if you have more, or you need better control at how your services are getting deployed, run and need more metrics and touch points, go for kubernetes.
If you want to keep your databases in containers, that I am not really sure about. Containers are lil volatile but collectively they give you high availability but for databases and rmq I personally will not keep them in containers for prod, but then you can read around and based on your need can decide on that.
Docker swarms and kubernetes can be used for dev and testing env as well. they can always run on single host.
yes you can do it like that you said, by creating a compose file per service, but if you want to keep it clean you can put them in one file like below :
version: '2'
services:
rabbitmq:
image: rabbitmqImg
networks:
- rabbitmq
keycloak:
image: keycloakImg
networks:
- keycloak
MS-A:
image: MSImg
networks:
- keycloak
MS-B:
image: MSImg
networks:
- keycloak
MS-C:
image: MSImg
networks:
- keycloak
- rabbitmq
MS-D:
image: MSImg
networks:
- keycloak
- rabbitmq
networks:
rabbitmq:
external:
name: rabbitmq
keycloak:
external:
name: keycloak
with this yaml microservices can talk to each other through keycloak network, all of microservices can talk to keycloak server also using keycloak network, and MS-C , MS-D can talk to rabbitmq through rabbitmq network. but if there is or will be some other microservices that doesnt need to talk to rabbitmq nor keycloak, you should create another network and put microservices in that and put microservices in other networks as they need.
as Anunay said you can use swarm mode or kubernetes but if you are beginner , stick to docker-compose, after that for scaling and orchestration you can use those frameworks.
EDIT: for databases there are multiple ways that depends on database architecture you have. for example if you have a database container per MS , you should create a network per MS like below:
version: '2'
services:
# General Services
rabbitmq:
image: rabbitmqImg
networks:
- rabbitmq
keycloak:
image: keycloakImg
networks:
- keycloak
# Micro Services
MS-A:
image: MSImg
networks:
- ms-a-net
- keycloak
MS-B:
image: MSImg
networks:
- ms-b-net
- keycloak
MS-C:
image: MSImg
networks:
- ms-c-net
- keycloak
- rabbitmq
MS-D:
image: MSImg
networks:
- ms-d-net
- keycloak
- rabbitmq
# Database Services
DB-A:
image: DBImg
networks:
- ms-a-net
DB-B:
image: DBImg
networks:
- ms-b-net
DB-C:
image: DBImg
networks:
- ms-c-net
DB-D:
image: DBImg
networks:
- ms-d-net
networks:
rabbitmq:
external:
name: rabbitmq
keycloak:
external:
name: keycloak
# Services Network
ms-a-net:
external:
name: ms-a-net
ms-b-net:
external:
name: ms-b-net
ms-c-net:
external:
name: ms-c-net
ms-d-net:
external:
name: ms-d-net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With