0
0
Dockerdevops~5 mins

Copying files to and from containers in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What command copies files from your local machine to a Docker container?
Use docker cp <local_path> <container_id>:<container_path> to copy files from your local machine to a container.
Click to reveal answer
beginner
How do you copy files from a Docker container to your local machine?
Use docker cp <container_id>:<container_path> <local_path> to copy files from a container to your local machine.
Click to reveal answer
beginner
Can you copy directories using docker cp?
Yes, docker cp supports copying entire directories between your local machine and containers.
Click to reveal answer
intermediate
What happens if the destination path does not exist when copying files with docker cp?
Docker will create the destination directory if it does not exist when copying directories. For files, the parent directory must exist.
Click to reveal answer
intermediate
Is it possible to copy files between two running containers directly using docker cp?
No, docker cp works only between your local machine and a container. To copy between containers, copy to local first, then to the other container.
Click to reveal answer
Which command copies a file named app.log from your local machine to the /var/log directory inside a container with ID abc123?
Adocker cp app.log abc123:/var/log
Bdocker copy app.log abc123:/var/log
Cdocker transfer app.log abc123:/var/log
Ddocker move app.log abc123:/var/log
To copy a directory named data from a container xyz789 to your local machine, which command is correct?
Adocker copy xyz789:/data ./data
Bdocker cp ./data xyz789:/data
Cdocker cp xyz789:/data ./data
Ddocker cp data xyz789:/data
What will happen if you try to copy a file to a container path that does not exist?
ADocker will create the path and copy the file
BThe command will fail with an error
CDocker will overwrite the container
DThe file will be copied to the container root directory
Can you use docker cp to copy files directly between two running containers?
ANo, you must copy files to local first
BYes, by specifying both container IDs
CYes, but only for files smaller than 10MB
DNo, copying files is not supported by Docker
Which of these is NOT a valid use of docker cp?
ACopying a file from local to container
BCopying a file from container to local
CCopying a directory from container to local
DCopying files between two containers directly
Explain how to copy a file from your local machine into a running Docker container.
Think about source and destination order in the command.
You got /4 concepts.
    Describe the steps to copy a directory from a Docker container to your local machine.
    Remember the order: container path then local path.
    You got /4 concepts.