2015-05-26 30 views
24

Ho scritto un Dockerfile che assomiglia a questoCome copiare file da host per container usando Dockerfile

FROM ubuntu:12.04 

RUN apt-get update 
RUN apt-get install -y wget 

Ora sto avendo un file chiamato abc.txt nella mia macchina host. Come posso copiarlo in questo contenitore. C'è qualche passo che posso aggiungere in Dockerfile che copia da host a contenitore.

+0

tra l'altro, wget è già incluso in Ubuntu 12.04, se la memoria non mi serve – user2915097

+2

tuo Update e installare dovrebbe probabilmente essere collocato su una linea, vedi https://docs.docker.com/articles/dockerfile_best-practices/#run –

+0

vuoi il file in un'immagine _docker_ o solo in un contenitore _docker_? – Thomasleveil

risposta

36
comando

Usa COPY come questo:

COPY foo.txt /data/foo.txt 
# where foo.txt is the relative path on host 
# and /data/foo.txt is the absolute path in the image 

leggere ulteriori dettagli per la copia in official documentation

Un'alternativa sarebbe usare ADD ma questa non è la procedura migliore se non si desidera utilizzare alcune funzioni avanzate di ADD come la decompressione dei file tar.gz. Se si desidera comunque utilizzare il comando ADD, farlo in questo modo:

ADD abc.txt /data/abc.txt 
# where abc.txt is the relative path on host 
# and /data/abc.txt is the absolute path in the image 

leggere maggiori dettagli per ADD nella official documentation

0
I faced this issue, I was not able to copy zeppelin [1GB] directory into docker conatiner. and getting issue "COPY failed: stat /var/lib/docker/tmp/docker-builder977188321/zeppelin-0.7.2-bin-all: no such file or directory" 

I am using docker Version: 17.09.0-ce and resolved issue by following steps. 
Step 1: copy zeppelin directory [which i want to copy into docker package]into directory contain "Dockfile" 
Step 2: edit Dockfile and add command [location where we want to copy] 
ADD ./zeppelin-0.7.2-bin-all /usr/local/ 
Step 3: go to directory which contain DockFile and run command [alternatives also available] 
docker build . 

Step 4: docker image created Successfully with logs 
Step 5/9 : ADD ./zeppelin-0.7.2-bin-all /usr/local/ 
---> 3691c902d9fe 
Step 6/9 : WORKDIR $ZEPPELIN_HOME 
---> 3adacfb024d8 .... 
Successfully built b67b9ea09f02 
Problemi correlati