How to copy a file to a Docker container

This tutorial shows how to copy a file from the host to a Docker container.

Run the following command:


docker cp file CONTAINER:/PATH

Here an example showing copying a file called test to the tmp directory named apache running in docker.
The script first list the files in the host, copy the file to the containerthe. Then it connects to the container

The output will be:

root@ubuntu:/tmp# ls
test

root@ubuntu:/tmp# docker cp test apache:/tmp

root@ubuntu:/tmp# docker exec -it apache bash
[root@574a0820f181 /]# cd /tmp/
[root@574a0820f181 tmp]# ls
test 

References:

Docker

Recent Comments