Calling commands on docker file

I am trying to use a dockerized version of a python library called Mustache.

This library contains a Python file called diff_mustache.py. Within the running docker session, the absolute path to a desired file is /mustache/mustache/diff_mustache.py. When running this dockerfile on my local machine, it’s necessary to call source ~/.bashrc on the dockerfile to activate the environment in which diff_mustache.py has access to its required dependencies. Then I can run diff_mustache.py. The command I use to call diff_mustache manually outside of Nextflow is:

docker run -it bskubi/mustache /bin/bash -c “source ~/.bashrc && python mustache/mustache/diff_mustache.py”

This displays the help menu for diff_mustache. Is there a way to do something equivalent from within Nextflow?

Did you try using the containerOptions process directive? Something like:

process FOO {
  container 'busybox:latest'
  containerOptions '-c "source ~/.bashrc && python mustache/mustache/diff_mustache.py"'

  ...
}

You can read more about it here.

I don’t think containerOptions would work here for sourcing the file, but you could use it to set an environment variable such as PATH to help you? There is also docker.runOptions for a Docker specific set or args.

But the easiest option is to fix the container so it’s ready to use out of the box.

Not sure if you meant this, but the issue with runOptions (for clarity to other readers here) is that it applies to all processes, and as this question is related to a tool, I’d assume it’s specific to one or some but not all processes of the pipeline. I agree that the best solution is to fix the container image.

Sourcing files like that is always tricky, as this file is not necessarily on the same place depending on the compute environment. Fixing the container image should be the way to go.