0
0
Dockerdevops~5 mins

COPY instruction for adding files in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the COPY instruction do in a Dockerfile?
The COPY instruction copies files or directories from the build context on your computer into the Docker image at a specified path.
Click to reveal answer
beginner
How do you copy a single file named app.py from your local folder to the Docker image's /app directory?
Use the instruction: <br>COPY app.py /app/
Click to reveal answer
intermediate
Can the COPY instruction copy multiple files or folders at once?
Yes, you can copy multiple files or folders by listing them separated by spaces before the destination path, for example: <br>COPY file1.txt file2.txt /app/
Click to reveal answer
intermediate
What happens if the destination folder in COPY does not exist inside the image?
Docker will create the destination folder automatically before copying the files.
Click to reveal answer
intermediate
What is the difference between COPY and ADD instructions in Docker?
COPY only copies files and folders from the build context. ADD can also extract compressed files and fetch files from URLs, but COPY is preferred for simple copying because it is more predictable.
Click to reveal answer
Which Dockerfile instruction copies files from your computer into the image?
ARUN
BCOPY
CCMD
DEXPOSE
What happens if the destination folder in COPY does not exist?
AThe build fails with an error
BDocker ignores the COPY instruction
CFiles are copied to the root folder instead
DDocker creates the folder automatically
How do you copy multiple files in one COPY instruction?
AList all files separated by spaces before the destination
BUse multiple COPY instructions
CUse a wildcard * only
DYou cannot copy multiple files at once
Which instruction is preferred for simple file copying in Dockerfiles?
ACOPY
BADD
CRUN
DENV
Can COPY fetch files from a URL?
AOnly if the URL is inside the image
BYes, COPY can fetch from URLs
CNo, COPY only copies from local build context
DYes, but only for HTTPS URLs
Explain how the COPY instruction works in a Dockerfile and when you would use it.
Think about how you move files into a container image during build.
You got /4 concepts.
    Describe the difference between COPY and ADD instructions in Dockerfiles.
    Consider extra features ADD has beyond copying.
    You got /4 concepts.