# Using Zrok on docker for multiple services

**URL:** <https://openziti.discourse.group/t/using-zrok-on-docker-for-multiple-services/2757>\
**Category:** zrok\
**Created:** [June 21, 2024, 12:20pm UTC](https://openziti.discourse.group/t/using-zrok-on-docker-for-multiple-services/2757 "2024-06-21T12:20:12Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![stefanadelbert](https://yyz2.discourse-cdn.com/free1/user_avatar/openziti.discourse.group/stefanadelbert/32/2121_2.png) [@stefanadelbert](https://openziti.discourse.group/u/stefanadelbert)\
**Post date:** [July 3, 2024, 7:19am UTC](https://openziti.discourse.group/t/using-zrok-on-docker-for-multiple-services/2757/14 "2024-07-03T07:19:02Z")

</div>

I've been playing with this idea today as I'm also interested in multiple shares in a single environment from a single docker compose stack/swarm/instance/[insert proper term here].

What I'm showing here doesn't relate directly to the OP's question, but it's in the ballpark and might be interesting to some.

As a starting point, I used the compose file from [here](https://github.com/openziti/zrok/blob/main/docker/compose/zrok-private-share/compose.yml). Using the [`extends` feature of docker compose](https://docs.docker.com/compose/multiple-compose-files/extends/), you can write a kind of _zrok share template service_ and then use it to declare a service for each share in your compose file.

With the following two files in the same directory, try `docker compose up`.

Note services `zrok-share-1` and `zrok-share-2` and the use of `extends`.

`compose.yaml`

```yaml
services:
  zrok-init:
    image: busybox
    # matches uid:gid of "ziggy" in zrok container image
    command: chown -Rc 2171:2171 /mnt/.zrok
    user: root
    volumes:
      - zrok_env:/mnt/.zrok

  # enable zrok environment
  zrok-enable:
    image: ${ZROK_CONTAINER_IMAGE:-docker.io/openziti/zrok}
    depends_on:
      zrok-init:
        condition: service_completed_successfully
    entrypoint: zrok-enable.bash
    volumes:
      - zrok_env:/mnt
    environment:
      STATE_DIRECTORY: /mnt
      ZROK_ENABLE_TOKEN:
      ZROK_API_ENDPOINT:
      ZROK_ENVIRONMENT_NAME: docker-private-share

  zrok-share-1:
    extends:
      file: zrok-share.yaml
      service: zrok-share
    environment:
      ZROK_TARGET: 'http://localhost:8001'

  zrok-share-2:
    extends:
      file: zrok-share.yaml
      service: zrok-share
    environment:
      ZROK_TARGET: 'http://localhost:8002'

volumes:
  zrok_env:

networks:
  default:

```

`zrok-share.yaml`

```yaml
services:
  zrok-share:
    image: ${ZROK_CONTAINER_IMAGE:-docker.io/openziti/zrok}
    restart: no
    entrypoint:
    - bash
    - -euxc
    - |
      env
      echo "DEBUG: HOME=$${HOME}"
      ls -lA /mnt/.zrok/
      exec zrok share private --headless --backend-mode proxy "$${ZROK_TARGET}"
    depends_on:
      zrok-enable:
        condition: service_completed_successfully
    volumes:
      - zrok_env:/mnt
    environment:
      HOME: /mnt
      PFXLOG_NO_JSON: "true"

```

**Note** : In the `zrok-share.yaml`, I wasn't able to find a way to get `${ZROK_TARGET}` to resolve when it's used in the `command` element unless it's present in the `.env` file (which defeats the purpose). I _think_ that the `command` element is resolved at compose file parse time, but variables specified in the `environment` element are not available for resolution at that point. This is why the whole `zrok` command is spelled out in the `entrypoint` element.

---

_[View the full topic](https://openziti.discourse.group/t/using-zrok-on-docker-for-multiple-services/2757)._
