Converting docker-compose.yml into declaration

I’m trying to self-host Zulip server using docker containers.

This configuration of docker-compose.yml shows, among others:

version: "2"
services:
  memcached:
    image: "memcached:alpine"
    restart: unless-stopped
    command:
      - "sh"
      - "-euc"
      - |
        echo 'mech_list: plain' > "$$SASL_CONF_PATH"
        echo "zulip@$$HOSTNAME:$$MEMCACHED_PASSWORD" > "$$MEMCACHED_SASL_PWDB"
        echo "zulip@localhost:$$MEMCACHED_PASSWORD" >> "$$MEMCACHED_SASL_PWDB"
        exec memcached -S
    environment:
      SASL_CONF_PATH: "/home/memcache/memcached.conf"
      MEMCACHED_SASL_PWDB: "/home/memcache/memcached-sasl-db"
      MEMCACHED_PASSWORD: "REPLACE_WITH_SECURE_MEMCACHED_PASSWORD"

I don’t know how to properly translate servicesmemcachedcommand into Nix virtualisation.oci-containers.containers.<container> declaration.

I have already tried many options but with no luck.

What to do, when docker-compose.yml contains extra commands that overwrite default command (CMD from Dockerfile I suppose)? Or, in other words, how to “translate” such commands to declarative syntax and be sure that they will act the same as in mainstream’s docker-compose.yml?

Any help will be appreciated :slight_smile: Cheers!

The value of command in the YAML above is list of three strings. Unescaped and translated to Nix it would be:

virtualisation.oci-containers.containers.memcached.cmd = [
  "sh"
  "-euc"
  ''
    echo 'mech_list: plain' > "$SASL_CONF_PATH"
    echo "zulip@$HOSTNAME:$MEMCACHED_PASSWORD" > "$MEMCACHED_SASL_PWDB"
    echo "zulip@localhost:$MEMCACHED_PASSWORD" >> "$MEMCACHED_SASL_PWDB"
    exec memcached -S
  ''
];

maybe think about using nixos containers…you might have more fun with them…, in fact you’ll have a whale of a time, if your not using the whale…

@_Andrew thank you! It worked! After trying like dozens of different combinations of cmd, entrypoint, quoting, escaping, etc. I have my Zulip@Docker almost ready.

@nixinator Good point. I’d be happy to find out how to “translate” (even manually) docker-compose.yml files (lot’s of projects are using them in my programmer’s life) into NixOS containers. Do you know any good starting points for this adventure?

1 Like