Pre-command for steps in mono-repos

We use a mono-repo and I’m trying to move us from using hand crafted docker usage to the docker plugin, but since I don’t want to copy the whole repo (it is very large) into docker I need to run a “pre-command” in steps to cd into the right folder.

What is the best way to accomplish this? Using a pre-command hook applies it to all steps and I want to cd into different directories in each step.

One approach might be to use the docker-compose plugin with a docker-compose file that uses context (or the implicit build: ... form) to specify a more precise directory than the whole repository, e.g.

---
version: "3.7"
services:
  something:
    build: ./path/to/something

  other_thing
    build:
      context: ./path/to/other/thing
      args:
        SOME_ARG: 1

Thanks @huon I’ll give that a try!