Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wget in Dockerfile, files disappear in container

In a Docker file I use wget to download file in the image. But when I use this image in a docker-compose file, the container doesn't contains the files...

    FROM debian:8

    RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*

    RUN mkdir -p /blast  && cd /blast
    RUN wget ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/ncbi-blast-2.6.0+-x64-linux.tar.gz
    RUN tar zxvpf ncbi-blast-2.6.0+-x64-linux.tar.gz && rm ncbi-blast-2.6.0+-x64-linux.tar.gz
    RUN export PATH=$PATH:/blast/ncbi-blast-2.6.0+/bin
    #&& export BLASTDB=/blast/blastdb

    CMD ["sleep", "infinity"]

In the container I've the /blast folder, but not the files... Someon know how I can do a wget and keep files ? And why they disappear ?

EDIT

The docker history

    IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
    13361cc1dda8        9 minutes ago       /bin/sh -c #(nop)  CMD ["sleep" "infinity"]     0 B                 
    748afb9b0a0a        9 minutes ago       /bin/sh -c #(nop) WORKDIR /blast                0 B                 
    6eb2b58af7d4        9 minutes ago       /bin/sh -c export PATH=$PATH:/blast/ncbi-b...   0 B                 
    1331a22dcf67        10 minutes ago      /bin/sh -c wget ftp://ftp.ncbi.nlm.nih.gov...   675 MB              
    83d2844843e5        35 minutes ago      /bin/sh -c mkdir -p /blast  && cd /blast        0 B                 
    6b0b6a13ae47        41 minutes ago      /bin/sh -c apt-get update && apt-get insta...   41.2 MB             
    054abe38b1e6        12 hours ago        /bin/sh -c #(nop)  CMD ["/bin/bash"]            0 B                 
    <missing>           12 hours ago        /bin/sh -c #(nop) ADD file:712c48086043553...   123 MB         

The output of docker-compose build (extract part)

    2017-04-25 07:41:47 (10.1 MB/s) - 'ncbi-blast-2.6.0+-x64-linux.tar.gz' saved [222504398]

    ncbi-blast-2.6.0+/
    ncbi-blast-2.6.0+/ChangeLog
    ncbi-blast-2.6.0+/LICENSE
    ncbi-blast-2.6.0+/ncbi_package_info
    ncbi-blast-2.6.0+/doc/
    ncbi-blast-2.6.0+/doc/README.txt
    ncbi-blast-2.6.0+/bin/
    ncbi-blast-2.6.0+/bin/makeblastdb
    ncbi-blast-2.6.0+/bin/tblastx
    ncbi-blast-2.6.0+/bin/tblastn
    ncbi-blast-2.6.0+/bin/blastn
    ncbi-blast-2.6.0+/bin/blastdb_aliastool
    ncbi-blast-2.6.0+/bin/update_blastdb.pl
    ncbi-blast-2.6.0+/bin/windowmasker
    ncbi-blast-2.6.0+/bin/psiblast
    ncbi-blast-2.6.0+/bin/blastx
    ncbi-blast-2.6.0+/bin/rpsblast
    ncbi-blast-2.6.0+/bin/segmasker
    ncbi-blast-2.6.0+/bin/blastdbcheck
    ncbi-blast-2.6.0+/bin/rpstblastn
    ncbi-blast-2.6.0+/bin/deltablast
    ncbi-blast-2.6.0+/bin/makembindex
    ncbi-blast-2.6.0+/bin/convert2blastmask
    ncbi-blast-2.6.0+/bin/blastp
    ncbi-blast-2.6.0+/bin/dustmasker
    ncbi-blast-2.6.0+/bin/makeprofiledb
    ncbi-blast-2.6.0+/bin/blastdbcmd
    ncbi-blast-2.6.0+/bin/legacy_blast.pl
    ncbi-blast-2.6.0+/bin/blast_formatter
    ncbi-blast-2.6.0+/README
     ---> 1331a22dcf67
    Removing intermediate container 06070bb79e70
like image 843
mpiot Avatar asked Apr 25 '17 07:04

mpiot


People also ask

Can we use wget in Dockerfile?

Dockerfile to download a file using wget to current directory and copy the downloaded file to another directory.

Does Dockerfile need Workdir?

According to the documentation: The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn't exist, it will be created even if it's not used in any subsequent Dockerfile instruction.

Where are Dockerfiles saved?

The best way is to put the Dockerfile inside the empty directory and then add only the application and configuration files required for building the docker image. To increase the build's performance, you can exclude files and directories by adding a . dockerignore file to that directory as well.


1 Answers

group your RUN, do the wget and the tar in one RUN, something like

RUN wget ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/ncbi-blast-2.6.0+-x64-linux.tar.gz \ && tar zxvpf ncbi-blast-2.6.0+-x64-linux.tar.gz && rm ncbi-blast-2.6.0+-x64-linux.tar.gz

See the best practices for writing Dockerfile

https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

and use ENV instead of export in your Dockerfile

https://docs.docker.com/engine/reference/builder/#env

like image 134
user2915097 Avatar answered Sep 19 '22 14:09

user2915097