Man page - docker-container-cp(1)
Packages contains this manual
- docker-port(1)
- docker-manifest(1)
- docker-image-rm(1)
- docker-container-attach(1)
- docker-network-prune(1)
- docker-login(1)
- docker-system-df(1)
- docker-container-prune(1)
- docker-container-logs(1)
- docker-unpause(1)
- docker-trust(1)
- docker-images(1)
- docker-container-diff(1)
- docker-volume-update(1)
- docker-plugin-ls(1)
- docker-plugin-install(1)
- docker-context-use(1)
- docker-stack-rm(1)
- docker-swarm-init(1)
- docker-container-cp(1)
- docker-context-update(1)
- docker-builder-build(1)
- docker-rm(1)
- docker-swarm(1)
- docker-plugin-inspect(1)
- docker-stack-ls(1)
- docker-context-import(1)
- docker-builder(1)
- docker-container-stop(1)
- docker-container-restart(1)
- docker-stack-config(1)
- docker-network-ls(1)
- docker-container-create(1)
- docker-container-ls(1)
- docker-swarm-unlock-key(1)
- docker-config-inspect(1)
- docker-secret-create(1)
- docker-node-ls(1)
- docker-pause(1)
- docker-volume-inspect(1)
- docker-logs(1)
- docker-container-rm(1)
- docker-config-ls(1)
- docker-trust-sign(1)
- docker-swarm-join-token(1)
- docker-info(1)
- docker-image(1)
- docker-image-build(1)
- docker-run(1)
- docker-node-rm(1)
- docker-stack-services(1)
- docker-stack-ps(1)
- docker-container-kill(1)
- docker-container-start(1)
- docker-checkpoint-ls(1)
- docker-container-pause(1)
- docker-service-ls(1)
- docker-context-create(1)
- docker-system-prune(1)
- docker-service-logs(1)
- docker-plugin-set(1)
- docker-rename(1)
- docker-container-exec(1)
- docker-trust-signer-remove(1)
- docker-stack(1)
- docker-image-prune(1)
- docker-trust-key-generate(1)
- docker-node-inspect(1)
- docker-restart(1)
- docker-context-export(1)
- docker-top(1)
- docker-context(1)
- docker-swarm-join(1)
- docker-load(1)
- docker-service-inspect(1)
- docker-service-create(1)
- docker-swarm-ca(1)
- docker-service-scale(1)
- docker-network-rm(1)
- docker-wait(1)
- docker-manifest-create(1)
- docker-manifest-rm(1)
- docker-build(1)
- docker-volume-ls(1)
- docker-kill(1)
- docker-checkpoint-rm(1)
- docker-pull(1)
- docker-node-demote(1)
- docker-swarm-leave(1)
- docker-context-show(1)
- docker-image-save(1)
- docker-plugin(1)
- docker-context-inspect(1)
- docker-image-push(1)
- docker-builder-prune(1)
- docker-service(1)
- docker-secret-rm(1)
- docker-stats(1)
- docker-history(1)
- docker-export(1)
- docker-trust-revoke(1)
- docker-volume-prune(1)
- docker-service-ps(1)
- docker-rmi(1)
- docker-import(1)
- docker-swarm-unlock(1)
- docker-exec(1)
- docker(1)
- docker-system(1)
- docker-container(1)
- docker-stop(1)
- docker-node-ps(1)
- docker-image-load(1)
- docker-trust-signer(1)
- docker-container-port(1)
- docker-cp(1)
- docker-bake(1)
- docker-volume(1)
- docker-network-create(1)
- docker-container-run(1)
- docker-tag(1)
- docker-context-rm(1)
- docker-update(1)
- docker-context-ls(1)
- docker-service-rollback(1)
- docker-search(1)
- docker-image-pull(1)
- docker-config(1)
- docker-attach(1)
- docker-plugin-upgrade(1)
- docker-network(1)
- docker-config-create(1)
- docker-diff(1)
- docker-plugin-create(1)
- docker-system-events(1)
- docker-swarm-update(1)
- docker-events(1)
- docker-secret-inspect(1)
- docker-container-unpause(1)
- docker-container-commit(1)
- docker-plugin-disable(1)
- docker-secret-ls(1)
- docker-checkpoint(1)
- docker-start(1)
- docker-network-connect(1)
- docker-trust-signer-add(1)
- docker-container-top(1)
- docker-manifest-annotate(1)
- docker-commit(1)
- docker-config-json(5)
- docker-plugin-push(1)
- docker-network-inspect(1)
- docker-image-ls(1)
- docker-service-rm(1)
- docker-node(1)
- docker-volume-create(1)
- docker-image-history(1)
- docker-push(1)
- docker-plugin-enable(1)
- docker-container-stats(1)
- docker-secret(1)
- docker-ps(1)
- docker-image-inspect(1)
- docker-config-rm(1)
- docker-container-rename(1)
- docker-plugin-rm(1)
- docker-trust-inspect(1)
- docker-image-import(1)
- docker-service-update(1)
- docker-create(1)
- docker-container-update(1)
- docker-stack-deploy(1)
- docker-node-promote(1)
- docker-container-inspect(1)
- docker-node-update(1)
- docker-manifest-inspect(1)
- docker-checkpoint-create(1)
- docker-container-wait(1)
- docker-save(1)
- docker-trust-key-load(1)
- docker-system-info(1)
- docker-container-export(1)
- docker-network-disconnect(1)
- docker-image-tag(1)
- docker-inspect(1)
- docker-trust-key(1)
- docker-volume-rm(1)
- docker-manifest-push(1)
- docker-version(1)
- docker-logout(1)
- docker-port(1)
- docker-manifest(1)
- dockerd(8)
- docker-image-rm(1)
- docker-container-attach(1)
- docker-network-prune(1)
- docker-login(1)
- docker-system-df(1)
- docker-container-prune(1)
- docker-container-logs(1)
- docker-unpause(1)
- docker-trust(1)
- docker-images(1)
- docker-container-diff(1)
- docker-volume-update(1)
- docker-plugin-ls(1)
- docker-plugin-install(1)
- docker-context-use(1)
- docker-stack-rm(1)
- docker-swarm-init(1)
- docker-container-cp(1)
- docker-context-update(1)
- docker-builder-build(1)
- docker-rm(1)
- docker-swarm(1)
- docker-plugin-inspect(1)
- docker-stack-ls(1)
- docker-context-import(1)
- docker-builder(1)
- docker-container-stop(1)
- docker-container-restart(1)
- docker-stack-config(1)
- docker-network-ls(1)
- docker-container-create(1)
- docker-container-ls(1)
- docker-swarm-unlock-key(1)
- docker-config-inspect(1)
- docker-secret-create(1)
- docker-node-ls(1)
- docker-pause(1)
- docker-volume-inspect(1)
- docker-logs(1)
- docker-container-rm(1)
- docker-config-ls(1)
- docker-trust-sign(1)
- docker-swarm-join-token(1)
- docker-info(1)
- docker-image(1)
- docker-image-build(1)
- docker-run(1)
- docker-node-rm(1)
- docker-stack-services(1)
- docker-stack-ps(1)
- docker-container-kill(1)
- docker-container-start(1)
- docker-checkpoint-ls(1)
- docker-container-pause(1)
- docker-service-ls(1)
- docker-context-create(1)
- docker-system-prune(1)
- docker-service-logs(1)
- docker-plugin-set(1)
- docker-rename(1)
- docker-container-exec(1)
- docker-trust-signer-remove(1)
- docker-stack(1)
- docker-image-prune(1)
- docker-trust-key-generate(1)
- docker-node-inspect(1)
- docker-restart(1)
- docker-context-export(1)
- docker-top(1)
- docker-context(1)
- docker-swarm-join(1)
- docker-load(1)
- docker-service-inspect(1)
- docker-service-create(1)
- docker-swarm-ca(1)
- docker-service-scale(1)
- docker-network-rm(1)
- docker-wait(1)
- docker-manifest-create(1)
- docker-manifest-rm(1)
- docker-build(1)
- docker-volume-ls(1)
- docker-kill(1)
- docker-checkpoint-rm(1)
- docker-pull(1)
- docker-node-demote(1)
- docker-swarm-leave(1)
- docker-context-show(1)
- docker-image-save(1)
- docker-plugin(1)
- docker-context-inspect(1)
- docker-image-push(1)
- docker-builder-prune(1)
- docker-service(1)
- docker-secret-rm(1)
- docker-stats(1)
- docker-history(1)
- docker-export(1)
- docker-trust-revoke(1)
- docker-volume-prune(1)
- docker-service-ps(1)
- docker-rmi(1)
- docker-import(1)
- docker-swarm-unlock(1)
- docker-exec(1)
- docker(1)
- docker-system(1)
- docker-container(1)
- docker-stop(1)
- docker-node-ps(1)
- docker-image-load(1)
- docker-trust-signer(1)
- docker-container-port(1)
- docker-cp(1)
- docker-volume(1)
- docker-network-create(1)
- docker-container-run(1)
- docker-tag(1)
- docker-context-rm(1)
- docker-update(1)
- docker-context-ls(1)
- docker-service-rollback(1)
- docker-search(1)
- docker-image-pull(1)
- docker-config(1)
- docker-attach(1)
- docker-plugin-upgrade(1)
- docker-network(1)
- docker-config-create(1)
- docker-diff(1)
- docker-plugin-create(1)
- docker-system-events(1)
- docker-swarm-update(1)
- docker-events(1)
- docker-secret-inspect(1)
- docker-container-unpause(1)
- docker-container-commit(1)
- docker-plugin-disable(1)
- docker-secret-ls(1)
- docker-checkpoint(1)
- docker-start(1)
- docker-network-connect(1)
- docker-trust-signer-add(1)
- docker-container-top(1)
- docker-manifest-annotate(1)
- docker-commit(1)
- docker-config-json(5)
- docker-plugin-push(1)
- docker-network-inspect(1)
- docker-image-ls(1)
- docker-service-rm(1)
- docker-node(1)
- docker-volume-create(1)
- docker-image-history(1)
- docker-push(1)
- docker-plugin-enable(1)
- docker-container-stats(1)
- docker-secret(1)
- docker-ps(1)
- docker-image-inspect(1)
- docker-config-rm(1)
- docker-container-rename(1)
- docker-plugin-rm(1)
- docker-trust-inspect(1)
- docker-image-import(1)
- docker-service-update(1)
- docker-create(1)
- docker-container-update(1)
- docker-stack-deploy(1)
- docker-node-promote(1)
- docker-container-inspect(1)
- docker-node-update(1)
- docker-manifest-inspect(1)
- docker-checkpoint-create(1)
- docker-container-wait(1)
- docker-save(1)
- docker-trust-key-load(1)
- docker-system-info(1)
- docker-container-export(1)
- docker-network-disconnect(1)
- docker-image-tag(1)
- docker-inspect(1)
- docker-trust-key(1)
- docker-volume-rm(1)
- docker-manifest-push(1)
- docker-version(1)
- docker-logout(1)
- docker-port(1)
- docker-machine-os-apply(1)
- docker-manifest(1)
- docker-image-rm(1)
- docker-container-attach(1)
- dockerignore(5)
- docker-network-prune(1)
- docker-login(1)
- docker-system-df(1)
- docker-container-prune(1)
- docker-container-logs(1)
- docker-unpause(1)
- docker-images(1)
- docker-container-diff(1)
- docker-untag(1)
- docker-generate-spec(1)
- docker-pod-stop(1)
- docker-pod-ps(1)
- docker-system-connection-remove(1)
- docker-system-reset(1)
- docker-machine-ls(1)
- docker-container-cp(1)
- docker-rm(1)
- docker-image-search(1)
- docker-network-update(1)
- docker-container-stop(1)
- docker-container-restart(1)
- docker-network-ls(1)
- docker-container-create(1)
- docker-pod-create(1)
- docker-container-ls(1)
- docker-image-sign(1)
- docker-system-connection-list(1)
- docker-secret-create(1)
- docker-pause(1)
- docker-volume-inspect(1)
- docker-logs(1)
- docker-container-rm(1)
- docker-healthcheck(1)
- docker-system-service(1)
- docker-machine-reset(1)
- docker-system-migrate(1)
- docker-info(1)
- docker-image(1)
- docker-image-build(1)
- docker-pod-start(1)
- docker-run(1)
- docker-kube-play(1)
- docker-machine-inspect(1)
- docker-container-kill(1)
- docker-container-start(1)
- docker-pod-pause(1)
- docker-pod(1)
- docker-container-pause(1)
- docker-artifact-pull(1)
- docker-init(1)
- docker-system-prune(1)
- docker-farm-update(1)
- docker-container-ps(1)
- docker-rename(1)
- docker-container-exec(1)
- docker-play-kube(1)
- docker-volume-export(1)
- docker-image-prune(1)
- docker-completion(1)
- docker-healthcheck-run(1)
- docker-restart(1)
- docker-top(1)
- docker-pod-clone(1)
- docker-kube(1)
- docker-remote(1)
- docker-load(1)
- docker-pod-logs(1)
- docker-network-rm(1)
- docker-wait(1)
- docker-image-list(1)
- docker-kube-generate(1)
- docker-manifest-rm(1)
- docker-build(1)
- docker-umount(1)
- docker-manifest-create(1)
- docker-volume-ls(1)
- docker-artifact-ls(1)
- docker-kill(1)
- docker-generate(1)
- docker-pull(1)
- docker-volume-unmount(1)
- docker-machine(1)
- docker-artifact-rm(1)
- docker-image-save(1)
- docker-image-push(1)
- docker-image-diff(1)
- docker-container-runlabel(1)
- docker-secret-rm(1)
- docker-stats(1)
- docker-history(1)
- docker-export(1)
- docker-volume-prune(1)
- docker-image-unmount(1)
- docker-kube-apply(1)
- docker-image-umount(1)
- docker-rmi(1)
- docker-import(1)
- docker-machine-os(1)
- docker-exec(1)
- docker-artifact-push(1)
- docker-farm(1)
- docker-farm-build(1)
- docker-volume-exists(1)
- docker(1)
- docker-system(1)
- docker-container(1)
- docker-pod-stats(1)
- docker-stop(1)
- docker-manifest-add(1)
- docker-image-load(1)
- docker-container-exists(1)
- docker-kube-down(1)
- docker-container-port(1)
- docker-container-clone(1)
- docker-cp(1)
- docker-volume(1)
- docker-network-create(1)
- docker-container-run(1)
- docker-farm-remove(1)
- docker-tag(1)
- docker-manifest-exists(1)
- docker-machine-start(1)
- docker-image-trust(1)
- docker-update(1)
- docker-pod-exists(1)
- docker-pod-prune(1)
- docker-unmount(1)
- docker-auto-update(1)
- docker-system-connection-default(1)
- docker-search(1)
- docker-image-pull(1)
- docker-network(1)
- docker-attach(1)
- docker-pod-top(1)
- docker-system-connection-rename(1)
- docker-manifest-remove(1)
- docker-diff(1)
- docker-system-events(1)
- docker-image-scp(1)
- docker-network-reload(1)
- docker-unshare(1)
- docker-events(1)
- docker-secret-inspect(1)
- docker-container-unpause(1)
- docker-container-commit(1)
- docker-artifact(1)
- docker-system-connection(1)
- docker-secret-ls(1)
- docker-artifact-inspect(1)
- docker-start(1)
- docker-network-connect(1)
- docker-system-check(1)
- docker-container-mount(1)
- docker-machine-info(1)
- docker-container-top(1)
- docker-generate-kube(1)
- docker-system-renumber(1)
- docker-manifest-annotate(1)
- docker-artifact-add(1)
- docker-commit(1)
- docker-volume-import(1)
- docker-machine-ssh(1)
- docker-help(1)
- docker-network-inspect(1)
- docker-image-ls(1)
- docker-container-checkpoint(1)
- docker-farm-create(1)
- docker-volume-create(1)
- docker-image-history(1)
- docker-container-init(1)
- docker-container-restore(1)
- docker-pod-inspect(1)
- docker-push(1)
- docker-container-stats(1)
- docker-secret(1)
- docker-machine-stop(1)
- docker-system-connection-add(1)
- docker-image-untag(1)
- docker-ps(1)
- docker-image-inspect(1)
- docker-container-rename(1)
- docker-mount(1)
- docker-image-mount(1)
- docker-container-cleanup(1)
- docker-machine-rm(1)
- docker-pod-unpause(1)
- docker-image-import(1)
- docker-pod-kill(1)
- docker-create(1)
- docker-container-list(1)
- docker-container-update(1)
- docker-network-exists(1)
- docker-container-inspect(1)
- docker-volume-reload(1)
- docker-machine-set(1)
- dockerfile(5)
- docker-container-umount(1)
- docker-manifest-inspect(1)
- docker-machine-init(1)
- docker-image-tree(1)
- docker-container-wait(1)
- docker-farm-list(1)
- docker-save(1)
- docker-container-unmount(1)
- docker-system-info(1)
- docker-pod-rm(1)
- docker-container-export(1)
- docker-secret-exists(1)
- docker-pod-restart(1)
- docker-network-disconnect(1)
- docker-image-tag(1)
- docker-inspect(1)
- docker-machine-list(1)
- docker-image-exists(1)
- docker-volume-rm(1)
- docker-volume-mount(1)
- docker-manifest-push(1)
- docker-version(1)
- docker-logout(1)
- docker-generate-systemd(1)
apt-get install docker-ce-cli
apt-get install docker.io
apt-get install podman-docker
Manual
DOCKER
NAMESYNOPSIS
DESCRIPTION
EXAMPLES
OPTIONS
SEE ALSO
NAME
docker-container-cp - Copy files/folders between a container and the local filesystem
SYNOPSIS
|
docker container cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- |
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH |
DESCRIPTION
The docker container cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container’s file system to the local machine or the reverse, from the local filesystem to the container. If - is specified for either the SRC_PATH or DEST_PATH , you can also stream a tar archive from STDIN or to STDOUT . The CONTAINER can be a running or stopped container. The SRC_PATH or DEST_PATH can be a file or directory.
The docker container 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 docker container cp is run.
The cp command behaves like the Unix cp -a command in that directories are copied recursively with permissions preserved if possible. Ownership is set to the user and primary group at the destination. For example, files copied to a container are created with UID:GID of the root user. Files copied to the local machine are created with the UID:GID of the user which invoked the docker container cp command. If you specify the -L option, docker container cp follows any symbolic link in the SRC_PATH . docker container cp does not create parent directories for DEST_PATH if they do not exist.
Assuming a path separator of / , a first argument of SRC_PATH and second argument of DEST_PATH , the behavior is as follows:
|
• |
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 / |
•
|
Error condition: the destination directory must exist. |
||||
|
• |
DEST_PATH exists and is a file |
•
|
the destination is overwritten with the source file’s contents |
||||
|
• |
DEST_PATH exists and is a directory |
•
|
the file is copied into this directory using the basename from SRC_PATH |
|||
|
• |
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 |
•
|
Error condition: cannot copy a directory to a file |
||||
|
• |
DEST_PATH exists and is a directory |
•
|
SRC_PATH does not end with /. (that is: slash followed by dot ) |
•
|
the source directory is copied into this directory |
||||
|
• |
SRC_PATH does end with /. (that is: slash followed by dot ) |
•
|
the content of the source directory is copied into this directory |
The command requires SRC_PATH and DEST_PATH to exist according to the above rules. If SRC_PATH is local and is a symbolic link, the symbolic link, not the target, is copied by default. To copy the link target and not the link, specify the -L option.
A colon ( : ) is used as a delimiter between CONTAINER and its path. You can also use : when specifying paths to a SRC_PATH or DEST_PATH on a local machine, for example file:name.txt . 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‘
It is not possible to copy certain system files such as resources under /proc , /sys , /dev , tmpfs, and mounts created by the user in the container. However, you can still copy such files by manually running tar in docker exec . For example (consider SRC_PATH and DEST_PATH are directories):
$ docker exec foo tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | tar Cxf DEST_PATH -
or
$ tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | docker exec -i foo tar Cxf DEST_PATH -
Using - as the SRC_PATH streams the contents of STDIN as a tar archive. The command extracts the content of the tar to the DEST_PATH in container’s filesystem. In this case, DEST_PATH must specify a directory. Using - as the DEST_PATH streams the contents of the resource as a tar archive to STDOUT .
EXAMPLES
Suppose a container has finished producing some output as a file it saves to somewhere in its filesystem. This could be the output of a build job or some other computation. You can copy these outputs from the container to a location on your local host.
If you want to copy the /tmp/foo directory from a container to the existing /tmp directory on your host. If you run docker container cp in your ˜ (home) directory on the local host:
$ docker container cp compassionate_darwin:tmp/foo /tmp
Docker creates a /tmp/foo directory on your host. Alternatively, you can omit the leading slash in the command. If you execute this command from your home directory:
$ docker container cp compassionate_darwin:tmp/foo tmp
If ˜/tmp does not exist, Docker will create it and copy the contents of /tmp/foo from the container into this new directory. If ˜/tmp already exists as a directory, then Docker will copy the contents of /tmp/foo from the container into a directory at ˜/tmp/foo .
When copying a single file to an existing LOCALPATH , the docker container cp command will either overwrite the contents of LOCALPATH if it is a file or place it into LOCALPATH if it is a directory, overwriting an existing file of the same name if one exists. For example, this command:
$ docker container cp sharp_ptolemy:/tmp/foo/myfile.txt /test
If /test does not exist on the local machine, it will be created as a file with the contents of /tmp/foo/myfile.txt from the container. If /test exists as a file, it will be overwritten. Lastly, if /test exists as a directory, the file will be copied to /test/myfile.txt .
Next, suppose you want to copy a file or folder into a container. For example, this could be a configuration file or some other input to a long running computation that you would like to place into a created container before it starts. This is useful because it does not require the configuration file or other input to exist in the container image.
If you have a file, config.yml , in the current directory on your local host and wish to copy it to an existing directory at /etc/my-app.d in a container, this command can be used:
$ docker container cp config.yml myappcontainer:/etc/my-app.d
If you have several files in a local directory /config which you need to copy to a directory /etc/my-app.d in a container:
$ docker container cp /config/. myappcontainer:/etc/my-app.d
The above command will copy the contents of the local /config directory into the directory /etc/my-app.d in the container.
Finally, if you want to copy a symbolic link into a container, you typically want to copy the linked target and not the link itself. To copy the target, use the -L option, for example:
$ ln -s
/tmp/somefile /tmp/somefile.ln
$ docker container cp -L /tmp/somefile.ln
myappcontainer:/tmp/
This command copies content of the local /tmp/somefile into the file /tmp/somefile.ln in the container. Without -L option, the /tmp/somefile.ln preserves its symbolic link but not its content.
OPTIONS
|
-a , --archive [=false] |
Archive mode (copy all uid/gid information) |
||
|
-L , --follow-link [=false] |
Always follow symbol link in SRC_PATH |
||
|
-q , --quiet [=false] |
Suppress progress output during copy. Progress output is automatically suppressed if no terminal is attached |
SEE ALSO
docker-container(1)