Skip to main content
 首页 » 编程设计

python之当我尝试在 Docker 容器中运行 shell 脚本时无法打开文件

2025年05月04日23luoye11

我已经为此苦苦挣扎了一段时间,但我不知道自己做错了什么。我试图在容器内运行 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,显然找不到它。编辑您的 shell 脚本以通过其完整绝对路径引用 get_gene_length_filter.py:python/evolinc_docker/get_gene_length_filter.py。