# Using a container in a module

**URL:** <https://community.seqera.io/t/using-a-container-in-a-module/2025>\
**Category:** Ask for help\
**Created:** [March 29, 2025, 7:00pm UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025 "2025-03-29T19:00:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramirobarrantes](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ramirobarrantes/32/717_2.png) [@ramirobarrantes](https://community.seqera.io/u/ramirobarrantes)\
**Post date:** [March 29, 2025, 7:00pm UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/1 "2025-03-29T19:00:41Z")

</div>

I created a docker container with python and several packages which I put in my module. But then the process can’t locate the files the way it’s supposed to:

This is my module:

```auto
process TRANSFER_DATA {
    label 'process_single'
    container 'docker://rbarrant/champlain:0.1'

    input:
    tuple val(meta), val(info)

    output:
    tuple val(meta), val(info), emit: info

    when:
    task.ext.when == null || task.ext.when

    script:
    def source_directory=meta.id

    """
    python transfer_data.py ${source_directory} 
    """
}

```

But then I get: \>

> Command error:  
> python: can’t open file ‘transfer\_data.py’: [Errno 2] No such file or directory

And if for example I add

> #!/usr/bin/env python

at the beginning of the script then it can’t find the local directories (I.e. ${source\_directory}.

What am I missing?

---

<div class="post-metadata">

**Author:** ![pontus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/pontus/32/369_2.png) [@pontus](https://community.seqera.io/u/pontus)\
**Post date:** [March 29, 2025, 9:13pm UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/2 "2025-03-29T21:13:39Z")

</div>

`python transfer_data.py ...` doesn’t work because python will look for `transfer_data.py` in the current directory (where your process inputs are staged).

The `${source_directory}` likely doesn’t work because it’s probably a reference to something not in the container image - when executing containers, nextflow only binds in what is necessary (and the nextflow way is to accept it as a path - then nextflow will stage it in the work directory).

The `output` seems odd.

---

<div class="post-metadata">

**Author:** ![ramirobarrantes](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ramirobarrantes/32/717_2.png) [@ramirobarrantes](https://community.seqera.io/u/ramirobarrantes)\
**Post date:** [March 29, 2025, 10:11pm UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/3 "2025-03-29T22:11:02Z")

</div>

transfer\_data.py is in the bin directory, i have used that all the time and I can run this successfully in the conda environment. Definitely the ${source\_directory} is not in the container image. All that said, you make some good points about the binding. Mine is a very particular use case so I will ask about that separately.

---

<div class="post-metadata">

**Author:** ![paolo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/paolo/32/72_2.png) [@paolo](https://community.seqera.io/u/paolo)\
**Post date:** [March 30, 2025, 8:25pm UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/4 "2025-03-30T20:25:10Z")

</div>

Container names should \*not\* be prefixed with `docker://` or other (pseudo) protocol scheme

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [March 31, 2025, 7:00am UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/5 "2025-03-31T07:00:27Z")

</div>

For a script to be found in the `bin` directory you can’t call it using the interpreter.

e.g.,  
`python transfer_data.py` does not check the `PATH` variable for the script. Only the current directory.  
But `transfer_data.py` without the interpreter before (`python`) will look in the `PATH`, which the `bin/` folder is included in.

---

<div class="post-metadata">

**Author:** ![ramirobarrantes](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ramirobarrantes/32/717_2.png) [@ramirobarrantes](https://community.seqera.io/u/ramirobarrantes)\
**Post date:** [March 31, 2025, 11:01am UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/6 "2025-03-31T11:01:25Z")

</div>

Thank you @paolo , what should I put then? I did try various things but only this worked.

---

<div class="post-metadata">

**Author:** ![paolo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/paolo/32/72_2.png) [@paolo](https://community.seqera.io/u/paolo)\
**Post date:** [March 31, 2025, 11:15am UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/7 "2025-03-31T11:15:19Z")

</div>

If your container was uploaded to Docker hub the canonical name is `rbarrant/champlain:0.1`

---

<div class="post-metadata">

**Author:** ![paolo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/paolo/32/72_2.png) [@paolo](https://community.seqera.io/u/paolo)\
**Post date:** [March 31, 2025, 11:20am UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/8 "2025-03-31T11:20:48Z")

</div>

Regarding the error

```auto
Command error:
python: can’t open file ‘transfer_data.py’: [Errno 2] No such file or directory

```

you need to change the process script to

```auto
transfer_data.py ${source_directory} 

```

and `transfer_data.py` must have execute permissions. See [here](https://www.nextflow.io/docs/latest/sharing.html#the-bin-directory) for more details

---

<div class="post-metadata">

**Author:** ![ramirobarrantes](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ramirobarrantes/32/717_2.png) [@ramirobarrantes](https://community.seqera.io/u/ramirobarrantes)\
**Post date:** [April 7, 2025, 11:21am UTC](https://community.seqera.io/t/using-a-container-in-a-module/2025/9 "2025-04-07T11:21:38Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
