当我尝试在Docker容器中运行一个shell脚本时,无法打开文件
我一直在挣扎一段时间,我不知道我做错了什么。 我试图在容器中运行一个shell脚本,shell脚本从shell脚本所在的目录中读取一个python脚本。 但我得到这个错误,说`python:无法打开文件'get_gene_length_filter.py':[Errno 2]没有这样的文件或目录'。
这是我的Dockerfile:
FROM ubuntu:14.04.3 RUN apt-get update && apt-get install -y g++ \ make \ git \ zlib1g-dev \ python \ wget \ curl \ python-matplotlib \ python-numpy \ python-pandas ENV BINPATH /usr/bin ENV EVO2GIT https://upendra_35@bitbucket.org/upendra_35/evolinc_docker.git RUN git clone $EVO2GIT WORKDIR /evolinc_docker RUN chmod +x evolinc-part-I.sh && cp evolinc-part-I.sh $BINPATH RUN wget -O- http://cole-trapnell-lab.github.io/cufflinks/assets/downloads/cufflinks-2.2.1.Linux_x86_64.tar.gz | tar xzvf - RUN wget -O- https://github.com/TransDecoder/TransDecoder/archive/2.0.1.tar.gz | tar xzvf - ENV PATH /evolinc_docker/cufflinks-2.2.1.Linux_x86_64/:$PATH ENV PATH /evolinc_docker/TransDecoder-2.0.1/:$PATH ENTRYPOINT ["/usr/bin/evolinc-part-I.sh"] CMD ["-h"]
这是我的git回购代码:
#!/bin/bash # Create a directory to move all the output files mkdir output # Extracting classcode u transcripts, making fasta file, removing transcripts > 200 and selecting protein coding transcripts grep '"u"' $comparefile | gffread -w transcripts_u.fa -g $referencegenome - && python get_gene_length_filter.py transcripts_u.fa \ transcripts_u_filter.fa && TransDecoder.LongOrfs -t transcripts_u_filter.fa
这就是我如何运行它:
docker run --rm -v $(pwd):/working-dir -w /working-dir ubuntu/evolinc -c AthalianaslutteandluiN30merged.gtf -g TAIR10_chr.fasta
我将猜测并假设get_gene_length_filter.py
在/evolinc_docker
,在Dockerfile中声明的工作目录。 不幸的是,当你运行docker run ... -w /working-dir ...
,工作目录将是/working-dir
,所以Python将在/working-dir
寻找get_gene_length_filter.py
,它显然是未find。 编辑你的shell脚本来引用get_gene_length_filter.py
的完整绝对path: python /evolinc_docker/get_gene_length_filter.py
。
你的陈述
shell脚本从shell脚本所在的目录中读取一个python脚本。
是错的。
在您的shell脚本中 ,当您调用python get_gene_length_filter.py
, get_gene_length_filter.py
文件不会假定与shell脚本位于同一目录中,而是假定位于当前工作目录中。
要描述相对于当前shell脚本目录的path,请使用以下variables集 :
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
然后你可以调用你的python脚本:
python $SCRIPT_DIR/get_gene_length_filter.py
这样,你的shell脚本将工作在任何工作目录。