Can I run a service locally in docker-compose and have the proxy connect to it?

I’m interested in running a service locally in a docker-compose… how would I change the following to allow the proxy access to the service directly on the same docker network?

    environment:
      USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-host.docker.internal}
      USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}

I tried providing the service name, like this:

    environment:
      USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-sensordata-ingress}
      USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}

where sensordata-ingress is the name of the service that I would expect to be resolved by DNS, but the proxy doesn’t seem to be able to connect to sensordata-ingress:8080.

Here’s a sample Scala project with an explanation and config for doing that: akkaserverless-multiple-services-sample/service-two at main · johanandren/akkaserverless-multiple-services-sample · GitHub

1 Like

Thanks for the response Johan. I think you don’t understand what I’m asking. I want to run the services locally via docker-compose instead of having to run them with

sbt run

So in my case, I’ve already published to my local docker by issuing the following:

sbt docker:publishLocal

Now I want to run them locally in docker compose, as I mentioned above I can’t figure out how to tell the proxy where my USER_FUNCTION_HOST is. Besides the service name as shown above, I’ve also tried 0.0.0.0. You can see the message in the log for one of the proxies:

valid-metrics-logger-proxy_1        | {"timestamp":"2022-01-12T00:33:56.396Z","mdc":{"akkaAddress":"akka://akkaserverless-proxy@192.168.32.13:25520","akkaSource":"akka://akkaserverless-proxy/user/discovery-manager","sourceActorSystem":"akkaserverless-proxy"},"logger":"com.akkaserverless.proxy.DiscoveryManager","message":"Connecting to 0.0.0.0:8084 to discover the user function specification","severity":"INFO","thread":"akkaserverless-proxy-akka.actor.default-dispatcher-3"}

I indeed misunderstood the question!

The problem is probably that the built docker image binds the service to 127.0.0.1 by default (just like running locally, to not accidentally publish it to the world).

A docker-compose.yml file like this should do the trick:

version: "3"
services:
  my-service:
    image: my-first-service:HEAD-20220112-1731
    command: -Dakkaserverless.user-function-interface=0.0.0.0
  akka-serverless-proxy:
    image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.8.3
    command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
    ports:
      - "9000:9000"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      USER_FUNCTION_HOST: my-service
      USER_FUNCTION_PORT: 8080
      PUBSUB_EMULATOR_HOST: gcloud-pubsub-emulator
  gcloud-pubsub-emulator:
    image: gcr.io/google.com/cloudsdktool/cloud-sdk:341.0.0
    command: gcloud beta emulators pubsub start --project=test --host-port=0.0.0.0:8085
    ports:
      - 8085:8085

Note how I’m also not forwarding the service port to the host but instead let the containers talk to each other over the docker-compose internal network.

Great example, Johan! This is very helpful! Thank you!