Hi DO, I’m building a Node.js app which requires a Docker internal service, it needs to be able to access the Docker internal service (via env vars). Currently, I couldn’t find documentation anywhere talk about this. I couldn’t configure workers in deploy.template.yaml, either. My configuration: https://github.com/phuctm97/img-node/blob/master/.do/deploy.template.yaml

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hello, quickly looking at the linked repository it seems the API is trying to talk to the puppeteer worker via websockets. In App Platform workers are not exposed via HTTP. For this type of interaction you should use “internal services” rather than a worker. See internal_ports in app spec reference. Here is an example repo utilizing the concept (under the /multi route).

So in your case, I think the spec should look something like:

spec:
  name: img
  services:
    - name: api
      environment_slug: node-js
      git:
        branch: master
        repo_clone_url: https://github.com/phuctm97/img-node
      envs:
        - key: BROWSER_ENDPOINT
          scope: RUN_TIME
          value: "chrome:3000"
    - name: chrome
      environment_slug: docker
      image:
        repository: browserless/chrome
      internal_ports:
      - 3000

That should result in the api service exposed publicly, and the chrome service exposed internally on port 3000. Provided that browserless/chrome respects the PORT env parameter (quickly looking into the code on GitHub it looks like it should), that should make the puppeteer websocket service available to call from the api service.

Hope this helps!

  • Thanks a lot, @bojand. I’m actually trying it this way, but DO documentation said service is always publicly available, while worker is the same as service except for not publicly accessible, which is confusing.

    One other thing is I did discover DO doesn’t support the Deploy button for multi-services right now.

  • @bojand

    If I try to run your example I get the following error:

    Error: POST https://api.digitalocean.com/v2/apps: 400 errors validating app spec; first error in field "services.environment_slug": unrecognized environment_slug "docker"
    

    Removing the environment_slug leads to this error:

    Error: POST https://api.digitalocean.com/v2/apps: 400 error validating app spec field "services.image.registry_type": services.image.registry_type is required
    

    Any Idea how to fix this?

    • Hello, sorry I was just copying and pasting what original question had in their app spec at the time and modifying the relevant parts regarding communicating between services. But the spec is actually not 100% accurate / correct. environment_slug: docker is not a correct option for that property.

      To use a Docker image directly, you can use DigitalOcean Container Registry (DOCR), and upload an image there and use it like this:

      - name: chrome
        image:
          registry_type: DOCR
          repository: chrome
          tag: latest
      

      We do not support public docker hub images yet.

      Alternatively you could have a Dockerfile in the repository and use:

      dockerfile_path: Dockerfile
      

      in the App Spec, which is what the original poster eventually did.

      Hope this helps, sorry for the confusion.