Copying files from Docker container to host

后端 未结 18 2478
小蘑菇
小蘑菇 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:09

    Mount a "volume" and copy the artifacts into there:

    mkdir artifacts
    docker run -i -v ${PWD}/artifacts:/artifacts ubuntu:14.04 sh << COMMANDS
    # ... build software here ...
    cp  /artifacts
    # ... copy more artifacts into `/artifacts` ...
    COMMANDS
    

    Then when the build finishes and the container is no longer running, it has already copied the artifacts from the build into the artifacts directory on the host.

    Edit

    Caveat: When you do this, you may run into problems with the user id of the docker user matching the user id of the current running user. That is, the files in /artifacts will be shown as owned by the user with the UID of the user used inside the docker container. A way around this may be to use the calling user's UID:

    docker run -i -v ${PWD}:/working_dir -w /working_dir -u $(id -u) \
        ubuntu:14.04 sh << COMMANDS
    # Since $(id -u) owns /working_dir, you should be okay running commands here
    # and having them work. Then copy stuff into /working_dir/artifacts .
    COMMANDS
    

提交回复
热议问题