0
0
Dockerdevops~20 mins

Copying files to and from containers in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker File Copy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Copying a file from host to container
You run the command docker cp ./app/config.yaml mycontainer:/app/config.yaml. What is the expected result?
AThe command fails because the container name must be specified with a leading slash.
BThe command copies the entire app directory from the host to the container.
CThe file config.yaml is copied from the container's /app directory to the host's current directory.
DThe file config.yaml is copied from the host's current directory to /app inside the container named mycontainer.
Attempts:
2 left
💡 Hint
Remember the syntax is docker cp source_path container:destination_path to copy files into a container.
💻 Command Output
intermediate
2:00remaining
Copying a directory from container to host
What happens when you run docker cp mycontainer:/var/logs ./logs_backup?
AThe entire /var/logs directory from the container is copied to a new directory logs_backup on the host.
BOnly the files inside /var/logs are copied, but not the directory itself.
CThe command fails because the destination path on the host must be absolute.
DThe command copies the /var/logs directory from the host to the container.
Attempts:
2 left
💡 Hint
Check if the source is container:path and destination is host path.
Troubleshoot
advanced
2:00remaining
Why does this docker cp command fail?
You run docker cp /home/user/data.txt mycontainer:/data/ but get an error: Error: No such container:path: mycontainer:/data/. What is the most likely cause?
AThe docker cp command cannot copy files into directories inside containers.
BThe source file /home/user/data.txt does not exist on the host.
CThe container named mycontainer is not running or does not exist.
DThe destination path inside the container must not end with a slash.
Attempts:
2 left
💡 Hint
Check if the container name is correct and the container is running.
Best Practice
advanced
2:00remaining
Best practice for copying large files into containers
Which approach is best when you need to copy a large file repeatedly into a container during development?
AMount the host directory containing the file as a volume inside the container.
BUse docker cp every time you need to copy the file.
CRebuild the container image with the file included each time.
DUse scp to copy the file into the container's IP address.
Attempts:
2 left
💡 Hint
Think about avoiding repeated copying and making changes instantly visible.
🔀 Workflow
expert
3:00remaining
Order the steps to copy a file from host to a running container and verify it
Arrange these steps in the correct order to copy a file named settings.json from the host to a running container named webapp and verify the copy.
A1,4,2,3
B4,1,2,3
C4,2,1,3
D2,4,1,3
Attempts:
2 left
💡 Hint
You must confirm the container is running before copying files.