github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/docs/source/markdown/podman-cp.1.md (about)

     1  % podman-cp(1)
     2  
     3  ## NAME
     4  podman\-cp - Copy files/folders between a container and the local filesystem
     5  
     6  ## SYNOPSIS
     7  **podman cp** [*options*] [*container*:]*src_path* [*container*:]*dest_path*
     8  
     9  **podman container cp** [*options*] [*container*:]*src_path* [*container*:]*dest_path*
    10  
    11  ## DESCRIPTION
    12  Copies the contents of **src_path** to the **dest_path**. You can copy from the container's filesystem to the local machine or the reverse, from the local filesystem to the container.
    13  If - is specified for either the SRC_PATH or DEST_PATH, you can also stream a tar archive from STDIN or to STDOUT.
    14  
    15  The CONTAINER can be a running or stopped container. The **src_path** or **dest_path** can be a file or directory.
    16  
    17  The **podman cp** command assumes container paths are relative to the container's / (root) directory.
    18  
    19  This means supplying the initial forward slash is optional;
    20  
    21  The command sees **compassionate_darwin:/tmp/foo/myfile.txt** and **compassionate_darwin:tmp/foo/myfile.txt** as identical.
    22  
    23  Local machine paths can be an absolute or relative value.
    24  The command interprets a local machine's relative paths as relative to the current working directory where **podman cp** is run.
    25  
    26  Assuming a path separator of /, a first argument of **src_path** and second argument of **dest_path**, the behavior is as follows:
    27  
    28  **src_path** specifies a file
    29    - **dest_path** does not exist
    30  	- the file is saved to a file created at **dest_path**
    31    - **dest_path** does not exist and ends with /
    32  	- Error condition: the destination directory must exist.
    33    - **dest_path** exists and is a file
    34  	- the destination is overwritten with the source file's contents
    35    - **dest_path** exists and is a directory
    36  	- the file is copied into this directory using the basename from **src_path**
    37  
    38  **src_path** specifies a directory
    39    - **dest_path** does not exist
    40  	- **dest_path** is created as a directory and the contents of the source directory are copied into this directory
    41    - **dest_path** exists and is a file
    42  	- Error condition: cannot copy a directory to a file
    43    - **dest_path** exists and is a directory
    44  	- **src_path** ends with /
    45  		- the source directory is copied into this directory
    46  	- **src_path** ends with /. (that is: slash followed by dot)
    47  		- the content of the source directory is copied into this directory
    48  
    49  The command requires **src_path** and **dest_path** to exist according to the above rules.
    50  
    51  If **src_path** is local and is a symbolic link, the symbolic target, is copied by default.
    52  
    53  A colon (:) is used as a delimiter between CONTAINER and its path.
    54  
    55  You can also use : when specifying paths to a **src_path** or **dest_path** on a local machine, for example, `file:name.txt`.
    56  
    57  If you use a : in a local machine path, you must be explicit with a relative or absolute path, for example:
    58  	`/path/to/file:name.txt` or `./file:name.txt`
    59  
    60  ## OPTIONS
    61  
    62  #### **--extract**
    63  
    64  Extract the tar file into the destination directory. If the destination directory is not provided, extract the tar file into the root directory.
    65  
    66  #### **--pause**
    67  
    68  Pause the container while copying into it to avoid potential security issues around symlinks. Defaults to *true*. On rootless containers with cgroups V1, defaults to false.
    69  
    70  ## ALTERNATIVES
    71  
    72  Podman has much stronger capabilities than just `podman cp` to achieve copy files between host and container.
    73  
    74  Using standard podman-mount and podman-umount takes advantage of the entire linux tool chain, rather
    75  then just cp.
    76  
    77  If a user wants to copy contents out of a container or into a container, they can execute a few simple commands.
    78  
    79  You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container.
    80  
    81  If you want to copy the /etc/foobar directory out of a container and onto /tmp on the host, you could execute the following commands:
    82  
    83  	mnt=$(podman mount CONTAINERID)
    84  	cp -R ${mnt}/etc/foobar /tmp
    85  	podman umount CONTAINERID
    86  
    87  If you want to untar a tar ball into a container, you can execute these commands:
    88  
    89  	mnt=$(podman mount CONTAINERID)
    90  	tar xf content.tgz -C ${mnt}
    91  	podman umount CONTAINERID
    92  
    93  One last example, if you want to install a package into a container that
    94  does not have dnf installed, you could execute something like:
    95  
    96  	mnt=$(podman mount CONTAINERID)
    97  	dnf install --installroot=${mnt} httpd
    98  	chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
    99  	podman umount CONTAINERID
   100  
   101  This shows that using `podman mount` and `podman umount` you can use all of the
   102  standard linux tools for moving files into and out of containers, not just
   103  the cp command.
   104  
   105  ## EXAMPLE
   106  
   107  podman cp /myapp/app.conf containerID:/myapp/app.conf
   108  
   109  podman cp /home/myuser/myfiles.tar containerID:/tmp
   110  
   111  podman cp containerID:/myapp/ /myapp/
   112  
   113  podman cp containerID:/home/myuser/. /home/myuser/
   114  
   115  podman cp --extract /home/myuser/myfiles.tar.gz containerID:/myfiles
   116  
   117  podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
   118  
   119  ## SEE ALSO
   120  podman(1), podman-mount(1), podman-umount(1)