DEV Community

Cover image for 4.Copy File to Docker Container
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

4.Copy File to Docker Container

Lab Information

The Nautilus DevOps team possesses confidential data on App Server 2 in the Stratos Datacenter. A container named ubuntu_latest is running on the same server.

Copy an encrypted file /tmp/nautilus.txt.gpg from the docker host to the ubuntu_latest container located at /usr/src/. Ensure the file is not modified during this operation.

Lab Solutions

βœ… Part 1: Exact KodeKloud Lab Guidelines (Exam-Safe Mode)
πŸ”‘ Step 0: Login to Application Server 2

From the jump host:

ssh steve@stapp02

Password:

Am3ric@

πŸ“‚ Step 1: Copy the file into the container

docker cp /tmp/nautilus.txt.gpg ubuntu_latest:/usr/src/
Enter fullscreen mode Exit fullscreen mode

πŸ” Step 2: Verify inside the container (MANDATORY)

docker exec ubuntu_latest ls -l /usr/src/
Enter fullscreen mode Exit fullscreen mode

Expected result

File nautilus.txt.gpg is present in /usr/src/

File name and size match (no modification)

⚠️ Common Lab Mistakes to Avoid

❌ Copying from container to host (wrong direction)

❌ Wrong container name (ubuntu_latest must match exactly)

❌ Wrong destination path

❌ Using scp or rsync instead of docker cp

🧠 Part 2: Simple Step-by-Step Explanation (Beginner Friendly)
πŸͺœ What are we doing?

The encrypted file already exists on the Docker host

We use Docker’s built-in copy command

Docker copies the file byte-for-byte (no changes)

πŸ” Command Breakdown
docker cp /tmp/nautilus.txt.gpg ubuntu_latest:/usr/src/

docker cp β†’ copy files between host and container

/tmp/nautilus.txt.gpg β†’ source file on host

ubuntu_latest: β†’ target container

/usr/src/ β†’ destination directory inside container

πŸ‘‰ This preserves the file exactly as-is.

🧠 Exam Memory Hook

docker cp = safe, direct, no modification

Always verify with:

docker exec ls


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)