Episode 11: Inspecting Image, Copying files into and from Docker
In this article, we will learn the way we can :
- Inspecting Image.
- Copy docker data into and from the container
1. Inspecting Image:
→ We may need more information on our dockerized project to store in the database (say node version, created date, docker exposed PORT)
STEP 1: We need to get an image ID whose data we need. We use the below command
docker ps -a
docker image
STEP 2: Paste the image ID in the below command
docker image inspect <docker-image-id>eg. docker image e6bed6a65a54
2. Copying Docker Files:
→ It is possible we can copy files from codebase to docker container and vice-versa.
→ Let us a file in our project to copy (say test/test-file-1.js)
a. Copying from Project to specific docker container
→ For this we need a docker container, we use the below command to create contained:
docker build . // Create Docker Image (copy image id)
docker run -p 3000:80 <image-ID> // Create Docker Container
docker ps -a // Copy recently created container id
→ We use the below command to paste it into the docker command
docker cp <source_file> <container-id-or-name>:/<directory-to-paste>// copy specific file inside a directoryeg1 docker cp test/test_file_1.js optimistic_wozniak:/test
// copy all files inside a directoryeg2 docker cp test/. optimistic_wozniak:/test
TRICK:
It is possible to check into a container
For this, we go to the docker section → expand our container
b. Copying from a specific docker container to Project
→ Also sometimes it happens containers is shared by our colleague or clients
→ We might need it in our project.
→ We now have the test file in our container, let us delete the project’s test files
→ The below command will help us copy from docker’s container to our project directory.
docker cp <container-id-or-name>:/<directory-to-copy> <source_file>eg. docker cp optimistic_wozniak:/test test
a. Before running the command:
b. After running the command:
When do we require this 🤔 ?
Eg. When we run the application from docker, reading the docker file in the container will be difficult. We can copy into our project and read from our favourite editor.
Video:
Closing Thoughts:
In this article, we have understood ways to get detailed information about docker images, copy files into and from the docker container.
Thank you for reading till the end 🙌 . If you enjoyed this article or learned something new, support me by clicking the share button below to reach more people and/or give me a follow on Twitter and subscribe Happy Learnings !! to see some other tips, articles, and things I learn about and share there.