I dont know what is happening here. Im executing a script that contains the following line:
var="${comand} bash -c \"export PATH=/local/Miniconda3/bin:$PATH >> ~/.bashrc; /local/Miniconda3/bin/python3 scripts/DNAscan.py ${var}\""
echo "${var}"
$var
The output of that line is:
sudo docker exec -it image bash -c "PATH=/local//Miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin >> ~/.bashrc; /local/Miniconda3/bin/python3 scripts/DNAscan.py -format fastq -in input_output/input/test_data.1.fq.gz -in2 input_output/input/test_data.2.fq.gz -reference hg38 -alignment -variantcalling -annotation -iobio -out input_output/output/ -BED"
Bur when I try to execute it from the script it gives me the following error:
>>: -c: line 1: unexpected EOF while looking for matching `"'
>>: -c: line 2: syntax error: unexpected end of file
What can I do to solve this ?
CodePudding user response:
You don't really want docker exec
here at all. This is a debugging tool that you can use to inspect a running container; I'd use it the same way I'd use a language-specific debugger like Python's pdb
.
If you want to run a one-off command like this, you can use docker run
. For example,
docker run \
--rm \ # clean up this container when done
-v "$PWD/data:/app/input_output" \ # make local files available in the container
my-image \ # image name to run
scripts/DNAscan.py \ # command to run
-format fastq \
-in input_output/input/test_data.1.fq.gz \
-in2 input_output/input/test_data.2.fq.gz \
-reference hg38 \
-alignment \
-variantcalling \
-annotation \
-iobio \
-out input_output/output/ \
-BED
The command you show does tries to write a .bashrc
file inside the container setting up $PATH
. However, most paths that run Docker containers don't actually read the .bashrc
file at all. In your image's Dockerfile, you can use the ENV
directive to set $PATH
.
ENV PATH=/local/Miniconda3/bin:$PATH
Now we've gotten rid of the bash -c
wrapper entirely, which will resolve your quoting problem.
#!/bin/sh
docker run --rm -v "$PWD/data:/app/input_output" my-image "$@"
The "$@"
syntax passes the wrapper script's arguments as the docker run
command argument, preserving any spaces or other punctuation in the argument list.