How to copy files from Kubernetes or Docker Container to local host

Copy file from and to a Kubernetes Container

By using the "kubectl cp" command , we can copy files / directories from and to and Kubernetes Container.

Copy file from Kubernetes POD to local host

Syntax :

# When POD is running in specific namespace 
kubectl cp /path/to/local/file <namespace>/<pod-name>:/path/to/directory/in/container

# Within default namespace
kubectl cp <pod-name>:/path/to/directory/in/container /path/to/local/file

Example :

kubectl cp cfe-service-pod-845556794d-jdwc6:/opt/cfe/logs/app.log /opt/cfe_dir/app.log

Copy file from local host to Kubernetes POD

Syntax :

# When POD is running in specific namespace 
kubectl cp /path/to/local/file <namespace>/<pod-name>:/path/to/directory/in/container

# Within default namespace
kubectl cp /path/to/local/file <pod-name>:/path/to/directory/in/container

Example :

kubectl cp /opt/cfe_dir/conf.properties cfe-service-pod-845556794d-jdwc6:/opt/cfe

Copy file from and to a Docker Container

By using the "docker cp" command , we can copy files / directories from and to and Docker Container.

Copy file from Docker Container to local host

Syntax :

docker cp <namespace>/<container-id>:/path/to/directory/in/container /path/to/local/file

Example :

docker cp cfe-service-container:/opt/cfe/logs/app.log /opt/cfe_dir/app.log

Copy file from local host to Docker Container

Syntax :

docker cp /path/to/local/file <namespace>/<container-id>:/path/to/directory/in/container

Example :

docker cp /opt/cfe_dir/conf.properties cfe-service-container:/opt/cfe
 

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

www.000webhost.com