Docker: Copier des fichiers du conteneur Docker pour accueillir

Mots clés : dockerdocker-containerfile-copyingdocker

meilleur 5 Réponses Docker: Copier des fichiers du conteneur Docker pour accueillir

vote vote

94

docker cp <containerId>:/file/path/within/container /host/path/target 
$ sudo docker cp goofy_roentgen:/out_read.jpg . 
$ sudo docker ps  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES 1b4ad9311e93        bamos/openface      "/bin/bash"         33 minutes ago      Up 33 minutes       0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp   goofy_roentgen 
$ sudo docker cp 1b4a:/out_read.jpg . 
vote vote

82

docker create -ti --name dummy IMAGE_NAME bash docker cp dummy:/path/to/file /dest/to/file docker rm -f dummy 
vote vote

75

mkdir artifacts docker run -i -v ${PWD}/artifacts:/artifacts ubuntu:14.04 sh << COMMANDS # ... build software here ... cp <artifact> /artifacts # ... copy more artifacts into `/artifacts` ... COMMANDS 
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 
vote vote

64

$ docker run --rm -iv${PWD}:/host-volume my-image sh -s <<EOF chown $(id -u):$(id -g) my-artifact.tar.xz cp -a my-artifact.tar.xz /host-volume EOF 
$ docker build -t my-image - <<EOF > FROM busybox > WORKDIR /workdir > RUN touch foo.txt bar.txt qux.txt > EOF Sending build context to Docker daemon  2.048kB Step 1/3 : FROM busybox  ---> 00f017a8c2a6 Step 2/3 : WORKDIR /workdir  ---> Using cache  ---> 36151d97f2c9 Step 3/3 : RUN touch foo.txt bar.txt qux.txt  ---> Running in a657ed4f5cab  ---> 4dd197569e44 Removing intermediate container a657ed4f5cab Successfully built 4dd197569e44  $ docker run --rm -iv${PWD}:/host-volume my-image sh -s <<EOF chown -v $(id -u):$(id -g) *.txt cp -va *.txt /host-volume EOF changed ownership of '/host-volume/bar.txt' to 10335:11111 changed ownership of '/host-volume/qux.txt' to 10335:11111 changed ownership of '/host-volume/foo.txt' to 10335:11111 'bar.txt' -> '/host-volume/bar.txt' 'foo.txt' -> '/host-volume/foo.txt' 'qux.txt' -> '/host-volume/qux.txt'  $ ls -n total 0 -rw-r--r-- 1 10335 11111 0 May  7 18:22 bar.txt -rw-r--r-- 1 10335 11111 0 May  7 18:22 foo.txt -rw-r--r-- 1 10335 11111 0 May  7 18:22 qux.txt 
vote vote

56

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 

Questions similaires