[Docker] Copy files from docker container to host

Introduction

There was a scene where I wanted to bring a file locally from a docker container. Make a note of what you have investigated there.

procedure

  1. Use the docker ps command to find out which docker container you want to copy the file to
  2. Copy the file from the container to the host using the docker cp command

The procedure for actually copying httpd.conf, which is the configuration file of the httpd container, from the container to the local (host) is shown as an example.

1. Find out which docker container you want to copy the file to.

Execute the following command to check the container ID.

$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                               NAMES
1c8caa876b98        httpd:2-alpine         "httpd-foreground"       24 hours ago        Up 24 hours         0.0.0.0:8080->80/tcp                fluentd_docker_httpd_1

From the above command, I found that the container ID is 1c8caa876b98.

2. Copy the file from the container to the host

Execute the following command to copy the file

//docker cp [Container ID]:[File path you want to copy] [The path you want to copy locally]
$ docker cp 1c8caa876b98:/usr/local/apache2/conf/httpd.conf conf/

$ ls conf/
./		../		httpd.conf

I was able to copy!

Summary

--Copy from docker container to host --Use docker cp command

docker cp [Container ID]:[File path you want to copy] [The path you want to copy locally]

Recommended Posts

[Docker] Copy files from docker container to host
Copy files from docker container to host (docker cp)
[Docker] How to access the host from inside the container. http://host.docker.internal:
How to get a heapdump from a Docker container
Setting to exit from Docker container with VScode
How to update pre-built files in docker container
Migrating from vargrant to docker
Push Docker images from GitHub Actions to GitHub Container Registry
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.
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Access MySQL on a Docker container from a local (host OS) Java program
ubuntu: 20.04 Consideration memo to output GUI (output xeyes) to host side in docker container
Error response from daemon: conflict: Conflict when trying to create Docker container, so solution
How to check the logs in the Docker container
I made a Docker container to run Maven
I was addicted to not being able to connect to AWS-S3 from the Docker container
Small Docker container
Temporarily move Docker environment from Mac to AWS
Docker for Windows: MySQL container does not start when migrating from Hyper-v to WSL2
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
Add files to jar files
Introduction to JAR files
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Migrate from JUnit 4 to JUnit 5
How to install Docker
From Java to Ruby !!
Docker container usage scene
Copy and paste the file contents in Ubuntu's Docker container
Let's write how to make API with SpringBoot + Docker from 0
[Note] Flow from docker installation to JupyterLab startup on ubuntu
Host specification when laravel php artisan serve in docker container
Generate JSON from JVM class files to see the hierarchy
Wait for the container service to start with docker healthcheck
[Docker context] ~ How to access docker in remote environment from VScode ~
Connect to AWS RDS from your local PC Docker environment