1podman-cp(1) General Commands Manual podman-cp(1)
2
3
4
6 podman-cp - Copy files/folders between a container and the local
7 filesystem
8
9
11 podman cp [options] [container:]src_path [container:]dest_path
12
13
14 podman container cp [options] [container:]src_path [con‐
15 tainer:]dest_path
16
17
19 podman cp allows copying the contents of src_path to the dest_path.
20 Files can be copied from a container to the local machine and vice
21 versa or between two containers. If - is specified for either the
22 SRC_PATH or DEST_PATH, one can also stream a tar archive from STDIN or
23 to STDOUT.
24
25
26 The containers can be either running or stopped and the src_path or
27 dest_path can be a file or directory.
28
29
30 *IMPORTANT: The podman cp command assumes container paths are relative
31 to the container's root directory (/), which means supplying the ini‐
32 tial forward slash is optional and therefore sees compassionate_dar‐
33 win:/tmp/foo/myfile.txt and compassionate_darwin:tmp/foo/myfile.txt as
34 identical.*
35
36
37 Local machine paths can be an absolute or relative value. The command
38 interprets a local machine's relative paths as relative to the current
39 working directory where podman cp is run.
40
41
42 Assuming a path separator of /, a first argument of src_path and second
43 argument of dest_path, the behavior is as follows:
44
45
46 src_path specifies a file:
47 - dest_path does not exist
48 - the file is saved to a file created at dest_path (note that par‐
49 ent directory must exist).
50 - dest_path exists and is a file
51 - the destination is overwritten with the source file's contents.
52 - dest_path exists and is a directory
53 - the file is copied into this directory using the base name from
54 src_path.
55
56
57 src_path specifies a directory:
58 - dest_path does not exist
59 - dest_path is created as a directory and the contents of the
60 source directory are copied into this directory.
61 - dest_path exists and is a file
62 - Error condition: cannot copy a directory to a file.
63 - dest_path exists and is a directory
64 - src_path ends with /
65 - the source directory is copied into this directory.
66 - src_path ends with /. (i.e., slash followed by dot)
67 - the content of the source directory is copied into this direc‐
68 tory.
69
70
71 The command requires src_path and dest_path to exist according to the
72 above rules.
73
74
75 If src_path is local and is a symbolic link, the symbolic target, is
76 copied by default.
77
78
79 A colon ( : ) is used as a delimiter between a container and its path,
80 it can also be used when specifying paths to a src_path or dest_path on
81 a local machine, for example, file:name.txt.
82
83
84 *IMPORTANT: while using a colon ( : ) in a local machine path, one must
85 be explicit with a relative or absolute path, for example:
86 /path/to/file:name.txt or ./file:name.txt*
87
88
89 Using - as the src_path streams the contents of STDIN as a tar archive.
90 The command extracts the content of the tar to the DEST_PATH in the
91 container. In this case, dest_path must specify a directory. Using - as
92 the dest_path streams the contents of the resource (can be a directory)
93 as a tar archive to STDOUT.
94
95
96 Note that podman cp ignores permission errors when copying from a run‐
97 ning rootless container. The TTY devices inside a rootless container
98 are owned by the host's root user and hence cannot be read inside the
99 container's user namespace.
100
101
102 Further note that podman cp does not support globbing (e.g., cp
103 dir/*.txt). To copy multiple files from the host to the container use
104 xargs(1) or find(1) (or similar tools for chaining commands) in con‐
105 junction with podman cp. To copy multiple files from the container to
106 the host, use podman mount CONTAINER and operate on the returned mount
107 point instead (see ALTERNATIVES below).
108
109
111 --archive, -a
112 Archive mode (copy all UID/GID information). When set to true, files
113 copied to a container have changed ownership to the primary UID/GID of
114 the container. When set to false, maintain UID/GID from archive
115 sources instead of changing them to the primary UID/GID of the destina‐
116 tion container. The default is true.
117
118
119 --overwrite
120 Allow directories to be overwritten with non-directories and vice
121 versa. By default, podman cp errors out when attempting to overwrite,
122 for instance, a regular file with a directory.
123
124
126 Podman has much stronger capabilities than just podman cp to achieve
127 copying files between the host and containers.
128
129
130 Using standard podman-mount(1) and podman-unmount(1) takes advantage of
131 the entire linux tool chain, rather than just cp.
132
133
134 copying contents out of a container or into a container, can be
135 achieved with a few simple commands. For example:
136
137
138 To copy the /etc/foobar directory out of a container and onto /tmp on
139 the host, the following commands can be executed:
140
141 mnt=$(podman mount CONTAINERID)
142 cp -R ${mnt}/etc/foobar /tmp
143 podman umount CONTAINERID
144
145
146
147 To untar a tar ball into a container, following commands can be exe‐
148 cuted:
149
150 mnt=$(podman mount CONTAINERID)
151 tar xf content.tgz -C ${mnt}
152 podman umount CONTAINERID
153
154
155
156 To install a package into a container that does not have dnf installed,
157 following commands can be executed:
158
159 mnt=$(podman mount CONTAINERID)
160 dnf install --installroot=${mnt} httpd
161 chroot ${mnt} rm -rf /var/log/dnf /var/cache/dnf
162 podman umount CONTAINERID
163
164
165
166 By using podman mount and podman unmount, one can use all of the stan‐
167 dard linux tools for moving files into and out of containers, not just
168 the cp command.
169
170
172 • Copy a file from host to a container.
173 podman cp /myapp/app.conf containerID:/myapp/app.conf
174
175
176
177 • Copy a file from a container to a directory on another con‐
178 tainer.
179 podman cp containerID1:/myfile.txt containerID2:/tmp
180
181
182
183 • Copy a directory on a container to a directory on the host.
184 podman cp containerID:/myapp/ /myapp/
185
186
187
188 • Copy the contents of a directory on a container to a directory
189 on the host.
190 podman cp containerID:/home/myuser/. /home/myuser/
191
192
193
194 • Copy a directory on a container into a directory on another.
195 podman cp containerA:/myapp containerB:/newapp
196
197
198
199 • Stream a tar archive from STDIN to a container.
200 podman cp - containerID:/myfiles.tar.gz < myfiles.tar.gz
201
202
203
204
205
207 podman(1), podman-mount(1), podman-unmount(1)
208
209
210
211 podman-cp(1)