DOCKER · Files · 8 min

Copy a report out of a container

Retrieve one file without opening an interactive shell.

Not completed

Your task

Copy /reports/report.txt from the running practice container to report.txt in your current folder.

What you’re aiming for

  • The host report contains synthetic report.
  • The original container remains running.

1. Prepare your practice folder

Use a running Docker engine in Linux container mode. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-docker-copy-container-report && cd opsrung-docker-copy-container-report

Run these setup commands in that folder:

SETUP — RUN ONCE
cat > Dockerfile <<'DOCKERFILE'
FROM alpine:3.22
RUN mkdir -p /reports && printf 'synthetic report\n' > /reports/report.txt
USER 65534:65534
CMD ["sleep","3600"]
DOCKERFILE
docker build -t opsrung-copy-container-report:practice .
docker run -d --name opsrung-copy-container-report --network none --read-only --cap-drop ALL --security-opt no-new-privileges opsrung-copy-container-report:practice

Docker may download the official Alpine image and, for the web task, its HTTP package. If an example container name already exists, use a different name consistently. If port 8088 is occupied, choose another free local port.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

docker cp accepts a container:path source.

Hint 2

The destination is a path on your computer.

Hint 3

Use docker cp CONTAINER:/reports/report.txt ./report.txt.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat report.txt
docker ps --filter name=opsrung-copy-container-report

What you should see

  • The host report contains synthetic report.
  • The original container remains running.

If your result differs: Compare the actual output with each goal. Keep your work inside this exercise’s folder and use only its named resources.

Compare with one possible solution
ONE POSSIBLE SOLUTION
docker cp opsrung-copy-container-report:/reports/report.txt ./report.txt

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Clean up this exercise

Only remove the example resources you created. Volume cleanup deletes that exercise’s saved sample data. Keep anything you need.

OPTIONAL CLEANUP
docker stop opsrung-copy-container-report
docker rm opsrung-copy-container-report
docker image rm opsrung-copy-container-report:practice

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.