Copy file into Docker container


Recommended Posts

On ver 6.2 rc2 the following works to copy a file from the flash drive into a running container.  But on 6.1.9 it doesn't.  On 6.1.9 it complains about the path.  Also the help for "docker cp" on 6.1.9 doesn't show an option to copy in, only to copy out of the docker container to the host.

 

 docker cp /boot/btsync be45c973020a:/opt/btsync/btsync

 

Is there a way to copy a file into a docker container running on 6.1.9?

Link to comment

Here is the difference in the help files.  On 6.1.9 the docker copy command is only one way??  Copy out only??

 

root@Tower619:~# docker cp --help

 

Usage: docker cp [OPTIONS] CONTAINER:PATH HOSTDIR|-

 

Copy files/folders from a PATH on the container to a HOSTDIR on the host

running the command. Use '-' to write the data as a tar file to STDOUT.

 

root@Tower62rc2:/boot# docker cp --help

 

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

        docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

 

Copy files/folders between a container and the local filesystem

Use '-' as the source to read a tar archive from stdin

and extract it to a directory destination in a container.

Use '-' as the destination to stream a tar archive of a

container source to stdout.

 

 

Link to comment

Volume map to a server location where the file is stored and simply copy it inside the docker?

 

Yes that works fine.  But is 6.1.9 missing the "docker cp" into container option??

 

It was probably added in a later version of docker, which 6.2 has.

Link to comment
  • 1 month later...

The following worked

 

Have an array disk or user share mapped into the container config area.  I have container /data mapped to unRaid array /disk2.

 

Then it is simply

 

docker ps
docker exec -t -i 37fcc75e886d /bin/bash  
cp /data/btsync ./btsyncnew
rename 's/btsync/oldsync/' *
rename 's/btsyncoldnew/btsync/' *
chmod 777 btsync

 

The rename was required as I couldn't copy over top of the same file.

"cp: cannot create regular file ‘/opt/btsync/btsync’: Text file busy"

 

Link to comment
  • 6 years later...

I have little linux knowledge so this had been difficult for me.  I have a docker (Valheim) with a file that I want to move to a new unraid server docker.  I can't seem to find the file with a search when I use the terminal from the docker itself.  When I use the Unraid terminal I cant figure out how to browse or search the docker drive.  Can I use docker cp if I don't know the location of the file?  Can I use docker cp to copy the file to a SMB share?

 

Thanks

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.