# Docker: how to run a script within nextflow?

**URL:** <https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385>\
**Category:** Ask for help\
**Created:** [January 12, 2024, 9:42pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385 "2024-01-12T21:42:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [January 12, 2024, 9:42pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/1 "2024-01-12T21:42:53Z")

</div>

Hi,  
I’ve a docker container which runs fine on command line as:

` docker exec vicc_test /bin/grandsonofvictor.py --output /full/path/ --sample_id M-0489 --type mutation --es_url elastic:name123@ec2-54-84-170-0.compute-1.amazonaws.com:9000 /path/annotated_variants.consensus.vcf`

I get output at `/full/path/`

`vicc_test` is the docker tag.

Now, I’m interested in running this inside nextflow process. I’ve code below as:

```auto
 process test {
 
 container 'sinaidgt/vicc-api:bc55e0123405932bf2042641bc'
     maxForks 3
         debug true
         errorStrategy 'retry'
     maxRetries 2
 publishDir path: "path/full/learn_nextflow/", mode: 'copy' , overwrite: true
 
 output:
  path "versions.yml" , emit: versions
 stdout
     script:
     """
 echo "hello"
  /bin/grandsonofvictor.py
"""
 }
 
 workflow {
     test()
 }

```

It fails with error:

> Command error:  
> hello  
> .command.sh: line 3: /bin/grandsonofvictor.py: No such file or directory

I have tried following as well:

```auto
./bin/grandsonofvictor.py
./grandsonofvictor.py
grandsonofvictor.py

```

But none of these have worked.

I am new to docker concept overall.

How do I get this working?

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [January 14, 2024, 2:06am UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/2 "2024-01-14T02:06:14Z")

</div>

If I understood well, `/bin/grandsonofvictor.py` is **not** inside the container image, but at the host operating system. It should be in a folder named `bin` in the project folder of the Nextflow pipeline. You seem to be providing it from the root (`/`) as `/bin/grandsonofvictor.py`. Try putting it at `./bin/grandsonofvictor.py` and giving it **+x** permission (`chmod +x ./bin/grandsonofvictor.py`. By doing these two things, Nextflow will automatically make sure `grandsonofvictor.py` is accessible from within the container image. You don’t need the `./bin/` when calling it in the process block.

---

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [January 14, 2024, 12:34pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/3 "2024-01-14T12:34:19Z")

</div>

Hi @mribeirodantas,

Thank you for looking into this.

I don’t think I understand and follow you. The grandsonofvictor is on docker.

I’ve a bin folder at the folder structure where I’m trying to run this nextflow script.  
I do not see `grandsonofvictor.py` inside the bin folder.

How do I chmod the victor script? At docker? Can you please help me further?

If I put the victor script inside bin folder when how would I use the docker?

I only put `grandsonofvictor.py` in the process block and run it, I get error as:

> .command.sh: line 4: grandsonofvictor.py: command not found

I also do not know how to copy scripts/files from docker to local.

I honestly do not understand docker and nextflow a layer on it is completely mysterious.

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [January 14, 2024, 3:18pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/4 "2024-01-14T15:18:25Z")

</div>

Ideally, you just let Nextflow take care of staging/moving files around. You shouldn’t have to worry about this.

I recommend you have a look at [this](https://training.nextflow.io/basic_training/containers/) section of the foundational training. It will help you understand what I meant in my previous post. Let me know if it’s not solved by then 😉

---

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [January 14, 2024, 6:10pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/5 "2024-01-14T18:10:23Z")

</div>

@mribeirodantas

I know nextflow takes care of moving and staging.

Thanks for sharing the link, I’ve combed through it before posting on the forum. It doesn’t solve the issue I’m at. Instead of command line, I mention docker image inside the process interested as there are multiple processes with different docker images.

Sorry, if my post wasn’t clearer - the docker has a bin folder and then a script there as `sonofwhatever.py`

How do I check that nextflow is inside or activated the docker container? Is there a way to list `ls` contents there?

Finally, how do I have that script **in** `bin` folder at _docker_ run?

Thanks for your replies.

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [January 15, 2024, 12:19pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/6 "2024-01-15T12:19:26Z")

</div>

If you’re sure the container image has a script named `sonofwhatever.py` at `/bin/`, and have configured Nextflow properly to use Docker with this container image for a specific process, I don’t see a reason for running into `command not found`. Can you share the container image so that I could try locally?

> [@complexgenome](#):
>
> How do I check that nextflow is inside or activated the docker container? Is there a way to list `ls` contents there?

You can check the contents of the `.command.run` file within the task folder [of the process you’re interested in]. There should be docker command lines in it, such as in the `nxf_launch` function below:

```auto
nxf_launch() {
    docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -v /Users/mribeirodantas:/Users/mribeirodantas -w "$PWD" --name $NXF_BOXID quay.io/nextflow/rnaseq-nf:v1.2.1 /bin/bash -c "eval $(nxf_container_env); /bin/bash -ue /Users/mribeirodantas/work/f8/765aa40b350963bfda54fe6043b9eb/.command.sh"
}

```

---

<div class="post-metadata">

**Author:** ![complexgenome](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/complexgenome/32/392_2.png) [@complexgenome](https://community.seqera.io/u/complexgenome)\
**Post date:** [January 15, 2024, 1:30pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/7 "2024-01-15T13:30:49Z")

</div>

Thank you for your reply.  
The image I was using wasn’t latest. Solved after correcting for the image.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [January 22, 2024, 1:31pm UTC](https://community.seqera.io/t/docker-how-to-run-a-script-within-nextflow/385/8 "2024-01-22T13:31:02Z")

</div>

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