Search code examples
dockerdocker-run

How to get files generated by docker run to host


I have run docker run to generate a file

sudo docker run -i --mount type=bind,src=/home/mathed/Simulation/custom_desman/1/Strains/Simulation2/Assembly,target=/home/mathed/Simulation/custom_desman/1/Strains/Simulation2/Assembly 990210oliver/mycc.docker:v1 MyCC.py /home/mathed/Simulation/custom_desman/1/Strains/Simulation2/Assembly/final_contigs_c10K.fa

This is the message I've got after executing.

20181029_0753
4mer
1_rename.py /home/mathed/Simulation/custom_desman/1/Strains/Simulation2/Assembly/final_contigs_c10K.fa 1000
Seqs >= 1000 : 32551
Minimum contig lengh for first stage clustering: 1236
run Prodigal.
/opt/prodigal.linux -i My.fa -a gene.aa -d gene.nuc -f gbk -o output -s potential_genes.txt
run fetchMG.
run UCLUST.
Get Feature.
2_GetFeatures_4mer.py for fisrt stage clustering
2_GetFeatures_4mer.py for second stage clustering
3_GetMatrix.py 1236 for fisrt stage clustering 
 22896 contigs entering first stage clustering
Clustering...
1_bhsne.py 20
2_ap.py /opt/ap 500 0
Cluster Correction.
to Split and Merge.
1_ClusterCorrection_Split.py 40 2
2_ClusterCorrection_Merge.py 40
Get contig by cluster.
20181029_0811

I now want to get the files generated by MyCC.py to host.
After reading Copying files from Docker container to host, I tried,

sudo docker cp 642ef90103be:/opt /home/mathed/data

But I got an error message

mkdir /home/mathed/data/opt: permission denied

Is there a way to get the files generated to a directory /home/mathed/data?
Thank you.


Solution

  • I assume your dest path does not exist. Docker cp doc stats that in that case :

    SRC_PATH specifies a directory
        DEST_PATH does not exist
            DEST_PATH is created as a directory and the contents of the source directory are copied into this directory
    

    Thus it is trying to create a directory fro DEST_PATH... and docker must have the rights to do so. According to the owner of the DEST_PATH top existing directory, you may have to either

    • create the directory first so that it will not be created by docker and give it the correct rights (looks like it has no rights to do so) using sudo chown {user}:{folder} + chmod +x {folder}
    • change the rights to the parent existing directory (chown + chmod again),
    • switch to path where docker is allowed to write.