What Docker instruction will you use to copy files from one layer to another layer when you are creating a Dockerfile?
Experience Level: Senior
Tags: Docker
Answer
Option 1: Copy a file from previous stage to a new stage:
FROM image AS stage1
# ...
FROM image AS stage2
COPY --from=stage1 /files /new-target-folder
Option 2: Copy a file from an external image as a "stage":
COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf
Related Docker job interview questions
What are the instructions that create layers in Docker?
Docker SeniorHow can you ensure that some files will be ignored by a build process and won't be copied as part of COPY instruction that is defined in a Dockerfile?
Docker SeniorWhat instructions do you use in Dockerfile to a previous stage as a new stage?
Docker SeniorWhat is the LABEL instruction good for in Docker?
Docker SeniorWhat is a difference between COPY and ADD instructions in Docker?
Docker Senior