Copying files from Docker container to host

后端 未结 18 2487
小蘑菇
小蘑菇 2020-11-22 13:39

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

18条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 14:00

    Mount a volume, copy the artifacts, adjust owner id and group id:

    mkdir artifacts
    docker run -i --rm -v ${PWD}/artifacts:/mnt/artifacts centos:6 /bin/bash << COMMANDS
    ls -la > /mnt/artifacts/ls.txt
    echo Changing owner from \$(id -u):\$(id -g) to $(id -u):$(id -g)
    chown -R $(id -u):$(id -g) /mnt/artifacts
    COMMANDS
    

    EDIT: Note that some of the commands like $(id -u) are backslashed and will therefore be processed within the container, while the ones that are not backslashed will be processed by the shell being run in the host machine BEFORE the commands are sent to the container.

提交回复
热议问题