Copy files from docker container to host (docker cp)

command

docker cp <Container ID or container name>:Path of the file you want to copy Copy destination path

Can be copied with. Click here for the reference.

Illustration

I'm running oracle with docker and want to check the connection information, so copy tnsnames.ora.

When container ID is specified


#Check container ID(CONTAINER ID)
$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                 PORTS                                            NAMES
d3e6c3fd1a85        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   2 hours ago         Up 2 hours (healthy)   0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   orcl

#make a copy
$ docker cp d3e6c3fd1a85:/opt/oracle/oradata/dbconfig/ORCLCDB/tnsnames.ora ./

#Check if you could copy
$ find tnsnames.ora
tnsnames.ora

When specifying the container name


#Look up the container name(NAMES) 
$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                 PORTS                                            NAMES
d3e6c3fd1a85        oracle/database:19.3.0-ee   "/bin/sh -c 'exec $O…"   2 hours ago         Up 2 hours (healthy)   0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   orcl

#make a copy
$ docker cp orcl:/opt/oracle/oradata/dbconfig/ORCLCDB/tnsnames.ora ./

#Check if you could copy
$ find tnsnames.ora
tnsnames.ora

Environmental information

$ docker version
Client: Docker Engine - Community
 Cloud integration  0.1.18
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 16:58:31 2020
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:07:04 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.7
BuildVersion:	19H2

reference

-Copy files between host and container with Docker -Copy files from Docker container to host -Install Oracle 19c on Mac with Docker and build a development environment

Recommended Posts

Copy files from docker container to host (docker cp)
[Docker] Copy files from docker container to host
[Docker] How to access the host from inside the container. http://host.docker.internal:
Setting to exit from Docker container with VScode
How to update pre-built files in docker container
Push Docker images from GitHub Actions to GitHub Container Registry
Migrating from vargrant to docker
Extract files from Docker Image
Introduction to Linux Container / Docker (Part 1)
Introduction to Linux Container / Docker (Part 2)
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
Update MySQL from 5.7 to 8.0 with Docker
How to share files with Docker Toolbox
Docker push to GitHub Container Registry (ghcr.io)
Investigate the replacement from Docker to Podman.
Access MySQL on a Docker container from a local (host OS) Java program
Run Embulk on Docker to convert files
ubuntu: 20.04 Consideration memo to output GUI (output xeyes) to host side in docker container
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Error response from daemon: conflict: Conflict when trying to create Docker container, so solution
I was addicted to not being able to connect to AWS-S3 from the Docker container
How to check the logs in the Docker container
I made a Docker container to run Maven
Temporarily move Docker environment from Mac to AWS
Small Docker container
Docker for Windows: MySQL container does not start when migrating from Hyper-v to WSL2
Cache Gradle dependent files to speed up docker build
Launch Docker from Java to convert Office documents to PDF
Steps to push Docker image to GitHub Container Registry (ghcr.io)
How to deploy to Heroku from a local docker image
List how to learn from Docker to AKS on AWS
Create a Docker container to convert EPS to PGF source
Communicate from the outside to the container launched by docker-compose
Ssh connect from container to git with VSCode Remote Container