Move Files from Host to Docker (version 1.7) Container

Yeah, I know. It looks pretty simple but apparently, up to the date of writing this post, moving files from your host inside your Docker containers is not yet achievable but it's included in the roadmap of version 1.8. Surprisingly enough, the opposite (From container to host is doable docker cp already). So how do we do it?


First find the container that you want to move your files into:

docker ps -l

the result will be something like the below:

CONTAINER ID        IMAGE                            COMMAND                CREATED             STATUS              PORTS                                                                                                                                NAMES
f54b160e2743        sequenceiq/hadoop-docker:2.7.0   "/etc/ -   2 minutes ago       Up 2 minutes        2122/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp   distracted_franklin

Use the CONTAINER_ID from above and issue the command:

cat $FILE_NAME | sudo docker exec -i $CONTAINER_ID sh -c 'cat > /path_to_pasted_file'

Voila! It's done! 😀😀😀

NOTE: This solution originally was Roel Van de Paar's and you can find the Docker's Github Issue discussion here.

The Rstats tag of this blog is added to R Bloggers