Open fntlnz opened 2 months ago
This is the nfx_launch command that it created
nxf_launch() {
sudo docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -e "AVARTHATSHOULDTOTALLYBETHERE" -v /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97:/tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97 -w "$NXF_TASK_WORKDIR" --name $NXF_BOXID ubuntu /bin/bash -ue /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97/.command.sh
}
as you can see the sudo
command does not pass down the needed env vars.
this seems to be a docker limitation?
@pditommaso no we just have to compose the nfx_launch
script in this way when using sudo
nxf_launch() {
sudo NXF_TASK_WORKDIR="$NXF_TASK_WORKDIR" AVARTHATSHOULDTOTALLYBETHERE="$AVARTHATSHOULDTOTALLYBETHERE" docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -e "AVARTHATSHOULDTOTALLYBETHERE" -v /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97:/tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97 -w "$NXF_TASK_WORKDIR" --name "$NXF_BOXID" ubuntu /bin/bash -ue /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97/.command.sh
}
instead of this
nxf_launch() {
sudo docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -e "AVARTHATSHOULDTOTALLYBETHERE" -v /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97:/tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97 -w "$NXF_TASK_WORKDIR" --name $NXF_BOXID ubuntu /bin/bash -ue /tmp/test-nf/work/aa/de499a28fb8da7677d285fc3941f97/.command.sh
}
and of course do the same thing in any other place where we do the same thing with sudo and the docker cli.
sorry don't get the difference
Got it, the variable must be passed before the docker
command. Likely it can be extended as general case
Bug report
Expected behavior and actual behavior
When running nextflow with
docker.sudo=true
and any env var inenvWhitelist
I expect the env vars to be available inside the process containers, however they are not, see additional context for more details.Steps to reproduce the problem
Open your nextflow config and write
Now run this pipeline
Program output
Environment
nextflow version 24.04.4.5917
Linux 6.8.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Tue Aug 13 13:35:26 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
zsh 5.9 (x86_64-ubuntu-linux-gnu)
Additional context
As a best practice, when you install the Docker daemon the installation process suggests you to not allow access to
/var/run/docker.sock
to your otherwise unprivileged user on the machine. This is because when a user gets added to thedocker
group it essentially becomes root since things like this can be donedocker run -it --privileged --net=host --pid=host debian nsenter -t 1 -n -m -p
.Following this best practice, one can configure Nextflow to ask for privileges when running docker in this way:
This works well indeed, however when used in combination with
docker.envWhitelist
. Why? BecauseenvWhitelist
will share the environment variables with the shell that is starting the sudo command here but the finaldocker run
command does not get the env vars in its/proc/self/environ
because they are not automatically passed down bysudo
. A possible solution to this problem is to run withsudo -E
, however a safer approach would be to forward only the whitelisted env vars.