Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy current directory in to docker image

When building my Docker image I need to copy all of the files in the same directory in to the Docker image.

I attempted to do this

ADD ./* $HOME/src

RUN ls $HOME/src

but it doesn't seem to work

ls: cannot access /root/src: No such file or directory

How would I go about copying all of the current directory and subdirectories in to my docker image while building?

like image 265
Qwertie Avatar asked Apr 06 '18 00:04

Qwertie


People also ask

How do I copy a folder using docker cp?

If you want to copy the /tmp/foo directory from a container to the existing /tmp directory on your host. If you run docker cp in your (home) directory on the local host: $ docker cp compassionate_darwin:tmp/foo /tmp Docker creates a /tmp/foo directory on your host.

Does copy in Dockerfile create directory?

Docker Dockerfiles COPY InstructionThe COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest> . Multiple <src> resource may be specified but they must be relative to the source directory that is being built (the context of the build).


2 Answers

Just add / at the end of src in ADD statement.

ADD ./* $HOME/src/
like image 83
MB11 Avatar answered Sep 23 '22 22:09

MB11


I was building the images using docker build - < Dockerfile which apparently doen't send the build context so things can't be copied. After changing to docker build . and adding the / like MB11 suggested the build worked.

like image 23
Qwertie Avatar answered Sep 23 '22 22:09

Qwertie