How to extract files from a docker image

Files can be extracted from a docker image using the docker cp command.

First, to run a docker container, use the following command:


docker run -d --name=mycontainer myimage

where myimage is the name of the docker image to extract the file from, and mycontainer is the name of the container.

Then, use the docker cp command to extract the file from the container, the command format is as follows:


docker cp <containerId>:/path/to/file /host/path/target

Among them, <containerId> is the ID of the container, which can be viewed by using the docker ps command; /path/to/file is the path of the file to be extracted in the container; /host/path/target is the path of the host to save the file.

For example, to extract the file /var/log/nginx/access.log from a container named mycontainer and save it to the host's /home/user directory, use the following command:


docker cp mycontainer:/var/log/nginx/access.log /home/user

Once the files are extracted, the container can be removed using the docker rm command:


docker rm mycontainer

おすすめ

転載: blog.csdn.net/txl910514/article/details/131043858