# How to handle in Nextflow docker mounting of symlinked files within a symlinked directory

**URL:** https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381
**Category:** Ask for help
**Tags:** nextflow
**Created:** [September 26, 2025, 9:04am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381 "2025-09-26T09:04:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jfy133](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jfy133/32/60_2.png) [@jfy133](https://community.seqera.io/u/jfy133)
#### Post date: [September 26, 2025, 9:04am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/1 "2025-09-26T09:04:01Z")

</div>

I’m struggling with an issue with nf-core modules I have made for building Kraken2.

For context, Kraken2 uses a directory as a database. To build the database, you have to execute two separate commands. In the first step you add all a collection of files to a directory. In the second command, you then execute the actual ‘build’ command that creates the custom files used by Kraken2 itself.

Following nf-core module structure, I have split these two steps into two separate modules. This structure also has the benefit because each of the two commands takes a long time. Therefore separating the two makes it more HPC friendly.

A user where I’m using this (nf-core/createtaxdb), has reported an issue in this system when using container systems. The second module (the ‘build’ one that receives the directory as input) fails when supplying the pipeline with a file on a local file system, because the tool cannot find one of the files inside the the received directory.

```auto
Command error: build_db: error opening taxonomy//nodes.dmp: No such file or directory

```

I’ve identified this as the problem with Docker not (being able to) follow the two layers of symlinks (i.e. the symlink of the original file on the filesystem into the directory, the directory of which is then symlinked from the first to the second process). I can identify this by taking the `docker run` command from the `.command.run` process, tweaking it to an interactive session, and looking inside. Files supplied via a URL into the module and thus staged into the working directory by Nextflow are accessible within the docker container, but the files on the local system have a red ‘broken link’ bash colour.

To demonstrate the problem, I’ve made a little-ish reprex of the issue

[kraken2-symlink-issue-reprex.zip](https://community.seqera.io/uploads/short-url/tHHsherP5quhqPaHPi67Zn0bUoZ.zip) (1.4 KB)

And you can run `nextflow run main.nf -c nextflow.config` , where you will get the error

```auto
Command error:cat: taxonomy/a_staged.txt: No such file or directory

```

I was wondering if anyone would have any suggestions if there is a work around to make Docker follow all the symlinks and if there is a way to get Nextflow to do this.

Workarounds I’ve found are:

- Use `stageAsMode 'copy'` but this is unsatisfying as duplicating the very large files will hit the disk
- Merging the two modules into one, but this is unsatisfying as it’s merging two very long running processes

One other suggestion I’ve been given (not yet tested) is to not export a directory from the first module, but all files and then ‘reconstruct’ the directory using `stageAs` in the downstream module

But the two tested workarounds are not great.

---

<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: [September 26, 2025, 10:43am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/2 "2025-09-26T10:43:45Z")

</div>

Doesn’t one also mount the entire work directory also if you have multiple symlinks? They’re relative right? Otherwise the whole filesystem structure needs to be mirrored inside.

---

<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: [September 26, 2025, 11:35am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/3 "2025-09-26T11:35:05Z")

</div>

I thought that should work at first, but I think the problem is that the first inputs are linked from outside of the work directory.

---

<div class="post-metadata">

### Author: ![nschan](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/nschan/32/1266_2.png) [@nschan](https://community.seqera.io/u/nschan)
#### Post date: [September 26, 2025, 11:47am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/4 "2025-09-26T11:47:38Z")

</div>

I agree with pontus, I think the problem is that the mounts are correctly resolved when the files are passed as inputs and the symlink during the first process works for that reason. When those files are then passed to process 2, they are still pointing to some place, but nextflow does not resolve the symlink when creating the container mounts, only the path to the symlink, therefore the symlink cannot be followed inside the second container.

Copying in solves that problem, another option may be to just pass the same set of files as inputs to the second process, so they are linked again for that process and the correct mounts are added during container start.

---

<div class="post-metadata">

### Author: ![jfy133](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jfy133/32/60_2.png) [@jfy133](https://community.seqera.io/u/jfy133)
#### Post date: [September 26, 2025, 12:25pm UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/5 "2025-09-26T12:25:23Z")

</div>

Yes exactly, what Pontus described that is the problem.

And I think @nschan also describes the behaviour I think that is happening too…

I was hoping someone may have a clever solution to get Nextflow to resolve all the symlinks but maybe indeed I have to just ‘reconstruct’ the directory structure of the databases in the second process

---

<div class="post-metadata">

### Author: ![jfy133](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jfy133/32/60_2.png) [@jfy133](https://community.seqera.io/u/jfy133)
#### Post date: [July 27, 2026, 8:23am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/6 "2026-07-27T08:23:04Z")

</div>

For future readers: In the end I did opt for reconstructing the output of the first module in the inputs of the second module using `stageAs`…

---

<div class="post-metadata">

### Author: ![jfy133](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jfy133/32/60_2.png) [@jfy133](https://community.seqera.io/u/jfy133)
#### Post date: [August 3, 2026, 8:24am UTC](https://community.seqera.io/t/how-to-handle-in-nextflow-docker-mounting-of-symlinked-files-within-a-symlinked-directory/2381/7 "2026-08-03T08:24:00Z")

</div>

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