0
0
Dockerdevops~20 mins

COPY instruction for adding files in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
COPY Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the result of this Dockerfile COPY command?
Given this Dockerfile snippet:
FROM alpine
COPY ./app /usr/src/app

What happens when you build this Docker image?
Docker
FROM alpine
COPY ./app /usr/src/app
AThe image build fails because the source path is missing a trailing slash.
BThe file 'app' is copied as '/usr/src/app' inside the image.
CThe image build ignores the COPY command and continues.
DThe local folder 'app' is copied into the image at '/usr/src/app'.
Attempts:
2 left
💡 Hint
COPY copies files or folders from your computer into the image.
🧠 Conceptual
intermediate
1:30remaining
Understanding relative paths in COPY instruction
In a Dockerfile, what does the source path in COPY refer to?
AThe path relative to the root directory of the host machine.
BThe absolute path inside the container filesystem.
CThe path relative to the Docker build context directory.
DThe path relative to the Dockerfile location.
Attempts:
2 left
💡 Hint
Think about where Docker looks for files when building.
Configuration
advanced
2:00remaining
Which COPY command correctly copies multiple files?
You want to copy two files, 'index.html' and 'style.css', from your local folder into '/usr/share/nginx/html' inside the image. Which COPY command is correct?
ACOPY index.html style.css /usr/share/nginx/html/
BCOPY ["index.html", "style.css", "/usr/share/nginx/html/"]
CCOPY index.html /usr/share/nginx/html/ style.css
DCOPY /usr/share/nginx/html/ index.html style.css
Attempts:
2 left
💡 Hint
COPY can take multiple source files followed by one destination folder.
Troubleshoot
advanced
2:30remaining
Why does this COPY command fail during build?
Dockerfile snippet:
FROM ubuntu
COPY ./config /etc/config

When building, you get an error: 'COPY failed: stat /var/lib/docker/tmp/...: no such file or directory'. What is the likely cause?
Docker
FROM ubuntu
COPY ./config /etc/config
AThe 'config' folder does not exist in the build context directory.
BDocker daemon does not have permission to write to '/etc/config'.
CThe Dockerfile syntax is incorrect; COPY needs a trailing slash on source.
DThe destination path '/etc/config' is invalid inside the container.
Attempts:
2 left
💡 Hint
Check if the source folder is present where Docker expects it.
Best Practice
expert
3:00remaining
What is the best practice for copying files to reduce Docker image size?
You want to copy only necessary files into your Docker image to keep it small. Which COPY instruction approach is best?
AUse .dockerignore to exclude unnecessary files and COPY only needed files.
BCOPY the entire project folder to avoid missing files.
CCOPY files one by one to control what is added.
DUse ADD instead of COPY to automatically extract archives.
Attempts:
2 left
💡 Hint
Think about how to prevent unwanted files from being sent to Docker build.