dockerdockerfiledocker-multi-stage-build

Docker cannot find files from first stage in multi-stage build


In the first stage of my build I use aws s3 cli to copy files from an s3 bucket to a folder called /tmp

In the second stage, I want to copy the contents of /tmp into a folder called inst/application/ (the parent folder needs to be created too).

I can see from my RUN ls command that the data is successfully copied from s3 in stage1. But I cannot seem to find it when attempting to copy from stage1 to stage2.

I feel like I'm missing some simple syntax or concept.

dockerfile

# stage 1: download app data from s3
FROM amazon/aws-cli as stage1
WORKDIR tmp
RUN aws s3 cp s3://rnaseqdata/ . --recursive
RUN ls -lhR ..

# stage 2
FROM rocker/shiny-verse:4.2.3 as stage2
COPY --from=stage1 /tmp ./inst/application
RUN ls -lah inst/application
CMD ["/bin/bash"]

Output from build:

#9 [stage1 4/4] RUN ls -lhR ..
#9 0.233 ..:
#9 0.233 total 4.0K
#9 0.233 drwxr-xr-x 1 root root 4.0K Mar 18 16:15 tmp
#9 0.233 
#9 0.233 ../tmp:
#9 0.233 total 23M
#9 0.233 -rw-r--r-- 1 root root 3.1M Mar 18 04:41 counts.rds
#9 0.233 -rw-r--r-- 1 root root 2.3M Mar 18 04:47 degs.rds
#9 0.233 -rw-r--r-- 1 root root 970K Mar 18 04:47 gene_anno.rds
#9 0.233 -rw-r--r-- 1 root root  484 Mar 18 04:47 metadata.rds
#9 0.233 -rw-r--r-- 1 root root  14K Mar 18 05:26 pca.rds
#9 0.233 -rw-r--r-- 1 root root 8.0M Mar 18 04:47 rpkm.rds
#9 0.233 -rw-r--r-- 1 root root 8.0M Mar 18 04:47 tpm.rds
#9 DONE 0.2s

and

#10 [stage2 2/3] COPY --from=stage1 /tmp ./inst/application
#10 DONE 0.0s

#11 [stage2 3/3] RUN ls -lah inst/application
#11 0.207 total 8.0K
#11 0.207 drwxr-xr-x 2 root root 4.0K Mar 18 16:27 .
#11 0.207 drwxr-xr-x 3 root root 4.0K Mar 18 16:27 ..
#11 DONE 0.2s

Solution

  • Choose one of two option Stage 1 WORKDIR /tmp #/ is addded

    or Stage 2 COPY --from=stage1 tmp ./inst/application # removed /