Multicontainer docker-compose.yml & resin environment variables

I have a simple docker-compose.yml file. I’d like to use the RESIN_MACHINE_NAME variable to define which docker image to pull. But I can’t seem to get it working. Here’s my config:

---
version: '2'
services:
  sidekick:
    restart: always
    privileged: true
    image: 'company/sidekick-resin:${RESIN_MACHINE_NAME}'

I’ve tried lots of combinations of ‘resin:’ + %%RESIN_MACHINE_NAME%% and other various approaches. Is there a right way to do this?

Hi, one note is that RESIN_MACHINE_NAME is not an environment variable, but a Dockerfile template variable, only available at the moment in Dockerfile.template files as %%RESIN_MACHINE_NAME%% (note, this is not the ${VARNAME} environment variable formatting), see more in the Dockerfile Templates docs.

We are planning to add support to template variables to docker-compose.yml, but the current workaround is the way that is shows in our getting started project:

You could basically create separate sidekick folder (or any other name) with just a Dockerfile.template of

FROM company/sidekick-resin:%%RESIN_MACHINE_NAME%%

(if that image has all your CMD and other setup as well). And in docker-compose.yml you’d use

services:
  sidekick:
    restart: always
    privileged: true
    build: ./sidekick
1 Like

Cool, that works for me. Thanks @imrehg!

1 Like

Hey @imrehg, is there any update on supporting template variables in docker-compose.yml?

Specifically, I want to bind ports to only my eth0 interface, but it needs to be dynamic for multiple devices.

current solution (only supports one device):

    ports:
      - '80:80'
      - '192.168.86.22:67:67/udp'
      - '192.168.86.22:53:53/udp'
      - '192.168.86.22:53:53/tcp'

ideal solution (where ETH0_IP is a custom device variable):

    ports:
      - "80:80"
      - "${ETH0_IP}:67:67/udp"
      - "${ETH0_IP}:53:53/udp"
      - "${ETH0_IP}:53:53/tcp"

Cheers,
Kyle

1 Like