Using Hydra with Docker

Hydra and HydraExpress apps require the use of a Redis server. If you're running your hydra-enabled microservice in a Docker container you'll need to ensure that your service can access Redis.

See this sample hello-service container

When using as a docker container you need to update the service's config file since the running container will have a different IP address from your host. So Redis won't be found inside the container!

There are a few ways to address this concern.

Method 1: Hardcode config.json on container build

The first method is to simply build the container with the hardcoded config entry for your Redis server.

Method 2: Use a DNS entry

Another option is to specify a DNS entry in your config file which maps to your Redis server. See the redislocation entry below.

  "environment": "development",
  "hydra": {
    "serviceName": "hello-service",
    "serviceIP": "",
    "servicePort": 5000,
    "serviceType": "hello",
    "serviceDescription": "says hello",
    "redis": {
      "url": "redis://redislocation:6379/15"

Next rebuild the container with the config above and then you can later run it using:

$ docker run -it -d -p 5000:5000 \
  --name hello-service \
  --add-host redislocation: \
  --workdir=/usr/src/app \

You can then test access the container's service using:

$ curl localhost:5000/v1/hello/test
{"statusCode":200,"statusMessage":"OK","statusDescription":"Request succeeded without error","result":{"msg":"hello from hello-service - da3a2e99becc03abed949080d8fa3185"}}

Method 3: Map a virtual folder

Yet, another method is to run the container with a mapped volume. In the example, the local project folder ~/dev/hello-service/config maps over the container's built-in /usr/src/app/config folder. So the running container will use the config file you specified in your project folder. That allows you to leave the config.json file in the container and override it with one outside the container.

$ docker run -it -d -p 5000:5000 \
  --name hello-service \
  --workdir=/usr/src/app \
  -v ~/dev/hello-service/config:/usr/src/app/config \

results matching ""

    No results matching ""