2018-08-30 08:41:19 +00:00
% podman-cp(1)
2017-11-01 15:24:59 +00:00
## NAME
2018-04-26 13:21:11 +00:00
podman\-cp - Copy files/folders between a container and the local filesystem
2017-11-01 15:24:59 +00:00
2019-01-07 16:16:29 +00:00
## SYNOPSIS
2019-03-20 14:15:56 +00:00
**podman cp** [*container*:]*src_path* [*container*:]*dest_path*
2019-01-07 16:16:29 +00:00
## DESCRIPTION
2019-03-20 14:15:56 +00:00
Copies the contents of **src_path** to the **dest_path** . You can copy from the containers's filesystem to the local machine or the reverse, from the local filesystem to the container.
2019-01-07 16:16:29 +00:00
2019-03-20 14:15:56 +00:00
The CONTAINER can be a running or stopped container. The **src_path** or **dest_path** can be a file or directory.
2019-01-07 16:16:29 +00:00
The **podman cp** command assumes container paths are relative to the container's / (root) directory.
This means supplying the initial forward slash is optional;
The command sees **compassionate_darwin:/tmp/foo/myfile.txt** and **compassionate_darwin:tmp/foo/myfile.txt** as identical.
Local machine paths can be an absolute or relative value.
The command interprets a local machine's relative paths as relative to the current working directory where **podman cp** is run.
2019-03-20 14:15:56 +00:00
Assuming a path separator of /, a first argument of **src_path** and second argument of **dest_path** , the behavior is as follows:
2019-01-07 16:16:29 +00:00
2019-03-20 14:15:56 +00:00
**src_path** specifies a file
- **dest_path** does not exist
- the file is saved to a file created at **dest_path**
- **dest_path** does not exist and ends with /
- **dest_path** is created as a directory and the file is copied into this directory using the basename from **src_path**
- **dest_path** exists and is a file
2019-01-07 16:16:29 +00:00
- the destination is overwritten with the source file's contents
2019-03-20 14:15:56 +00:00
- **dest_path** exists and is a directory
- the file is copied into this directory using the basename from **src_path**
2019-01-07 16:16:29 +00:00
2019-03-20 14:15:56 +00:00
**src_path** specifies a directory
- **dest_path** does not exist
- **dest_path** is created as a directory and the contents of the source directory are copied into this directory
- **dest_path** exists and is a file
2019-01-07 16:16:29 +00:00
- Error condition: cannot copy a directory to a file
2019-03-20 14:15:56 +00:00
- **dest_path** exists and is a directory
- **src_path** ends with /
2019-01-07 16:16:29 +00:00
- the source directory is copied into this directory
2019-03-20 14:15:56 +00:00
- **src_path** ends with /. (that is: slash followed by dot)
2019-01-07 16:16:29 +00:00
- the content of the source directory is copied into this directory
2019-03-20 14:15:56 +00:00
The command requires **src_path** and **dest_path** to exist according to the above rules.
2019-01-07 16:16:29 +00:00
2019-03-20 14:15:56 +00:00
If **src_path** is local and is a symbolic link, the symbolic target, is copied by default.
2019-01-07 16:16:29 +00:00
A colon (:) is used as a delimiter between CONTAINER and its path.
2019-03-20 14:15:56 +00:00
You can also use : when specifying paths to a **src_path** or **dest_path** on a local machine, for example, `file:name.txt` .
2019-01-07 16:16:29 +00:00
If you use a : in a local machine path, you must be explicit with a relative or absolute path, for example:
`/path/to/file:name.txt` or `./file:name.txt`
2019-03-04 21:49:27 +00:00
## OPTIONS
**--extract**
Extract the tar file into the destination directory. If the destination directory is not provided, extract the tar file into the root directory.
2019-01-07 16:16:29 +00:00
## ALTERNATIVES
Podman has much stronger capabilities than just `podman cp` to achieve copy files between host and container.
Using standard podman-mount and podman-umount takes advantage of the entire linux tool chain, rather
2017-11-01 15:24:59 +00:00
then just cp.
2019-01-07 16:16:29 +00:00
If a user wants to copy contents out of a container or into a container, they can execute a few simple commands.
2017-11-01 15:24:59 +00:00
2019-01-07 16:16:29 +00:00
You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container.
2017-11-01 15:24:59 +00:00
2019-01-07 16:16:29 +00:00
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:
2017-11-01 15:24:59 +00:00
2017-12-15 21:58:36 +00:00
mnt=$(podman mount CONTAINERID)
2017-11-01 15:24:59 +00:00
cp -R ${mnt}/etc/foobar /tmp
2017-12-15 21:58:36 +00:00
podman umount CONTAINERID
2017-11-01 15:24:59 +00:00
If you want to untar a tar ball into a container, you can execute these commands:
2017-12-15 21:58:36 +00:00
mnt=$(podman mount CONTAINERID)
2017-11-01 15:24:59 +00:00
tar xf content.tgz -C ${mnt}
2017-12-15 21:58:36 +00:00
podman umount CONTAINERID
2017-11-01 15:24:59 +00:00
One last example, if you want to install a package into a container that
does not have dnf installed, you could execute something like:
2017-12-15 21:58:36 +00:00
mnt=$(podman mount CONTAINERID)
2017-11-01 15:24:59 +00:00
dnf install --installroot=${mnt} httpd
chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
2017-12-15 21:58:36 +00:00
podman umount CONTAINERID
2017-11-01 15:24:59 +00:00
2017-12-15 21:58:36 +00:00
This shows that using `podman mount` and `podman umount` you can use all of the
2017-11-01 15:24:59 +00:00
standard linux tools for moving files into and out of containers, not just
the cp command.
2019-01-07 16:16:29 +00:00
## EXAMPLE
podman cp /myapp/app.conf containerID:/myapp/app.conf
podman cp /home/myuser/myfiles.tar containerID:/tmp
podman cp containerID:/myapp/ /myapp/
podman cp containerID:/home/myuser/. /home/myuser/
2019-03-04 21:49:27 +00:00
podman cp --extract /home/myuser/myfiles.tar.gz containerID:/myfiles
2017-11-01 15:24:59 +00:00
## SEE ALSO
2017-12-15 21:58:36 +00:00
podman(1), podman-mount(1), podman-umount(1)