How to transfer / copy files from docker container to local directory in ubuntu 18.04?

I am using ubuntu 18.04 with virtual machine for running my program in remote GPU server. I ran my program in docker and I want to transfer plot files in docker container to local file directory in my virtual machine. I used scp to transfer local files from virtual machine to docker container, but now I want to transfer result of my program, plot file back to local file directory in my virtual machine. How can I do this in Ubuntu? any idea?

here is what I did previously:

scp -P 8080 ./Downloads/my_func.py :data

for me, transferring files from local to remote docker container works pretty good, but reverse is not working or I made somewhere wrong in the command.

and this is list of files that currently resided in docker container(from docker shell):

root@d3576359f9ac:/data# ls
cnn_mobnet.py cnn_ResNet50.py cnn_mobnet_v1.py
cnn.py cnn_mobnet_loss_curve.png cnn_00.py mobnet_test.py

my attempt:

I tried to copy cnn_mobnet_loss_curve.png to local file directory in my virtual machine, but it doesn't work:

scp data/cnn_mobnet_loss_curve.png :./Downloads

I also tried docker cp data/cnn_mobnet_loss_curve.png :./Downloads but it gave me an error said docker command is not recognized. Any thought? From docker shell, how can I transfer or copy files in docker container to local file directory? Any thought?

where I want to copy or transfer cnn_mobnet_loss_curve.png in current docker container to ./Downloads which is in my virtual machine. How can I make this right? Any idea to transfer files from remote docker container to local in Ubuntu? How can I do this from terminal in Ubuntu? any idea?

2 Answers

docker ps

Then once you have your container ID, you can run the following:

docker cp container_id:/path/to/your_file.txt /path/on/your/host

I think you can do something like this should do what you want to do. Try this from your terminal:

me@myvirtualbox: ~$ scp -p 8080 :data/plot.png ./Downloads

you should provide your password for remote endpoint, and above solution should works for you.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like