Copying files from Docker container to host

2019-01-02 18:41发布

I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server, so that I don't have to install all the runtimes and libraries on the agents themselves. To achieve this I would need to copy the build artifacts that are built inside the container back into the host.

Is that possible?

14条回答
无与为乐者.
2楼-- · 2019-01-02 19:43

If you don't have a running container, just an image, and assuming you want to copy just a text file, you could do something like this:

docker run the-image cat path/to/container/file.txt > path/to/host/file.txt
明月照影归
3楼-- · 2019-01-02 19:44

Most of the answers do not indicate that the container must run before docker cp will work:

docker build -t IMAGE_TAG .
docker run -d IMAGE_TAG
CONTAINER_ID=$(docker ps -alq)
# If you do not know the exact file name, you'll need to run "ls"
# FILE=$(docker exec CONTAINER_ID sh -c "ls /path/*.zip")
docker cp $CONTAINER_ID:/path/to/file .
docker stop $CONTAINER_ID
查看更多
登录 后发表回答