Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Add every file in current directory

Tags:

docker

I have a simple web application that I would like to place in a docker container. The angular application exists in the frontend/ folder, which is withing the application/ folder.

When the Dockerfile is in the application/ folder and reads as follows:

FROM node
ADD frontend/ frontend/
RUN (cd frontend/; npm install;)
CMD (cd frontend/; npm start;)

everything runs correctly.

However, when I move the Dockerfile into the frontend/ folder and change it to read

FROM node
ADD . frontend/
RUN (cd frontend/; npm install;)
CMD (cd frontend/; npm start;)

no files are copied and the project does not run.

How can I add every file and folder recursively in the current directory to my docker image?

like image 607
iambicSam Avatar asked Feb 15 '17 00:02

iambicSam


People also ask

What does Workdir do in Docker?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.

What is difference between CMD and entrypoint?

Differences between CMD & ENTRYPOINT CMD commands are ignored by Daemon when there are parameters stated within the docker run command while ENTRYPOINT instructions are not ignored but instead are appended as command line parameters by treating those as arguments of the command.

Does Docker COPY COPY recursively?

The cp command behaves like the Unix cp -a command in that directories are copied recursively with permissions preserved if possible. Ownership is set to the user and primary group at the destination. For example, files copied to a container are created with UID:GID of the root user.

Can we have multiple Workdir in Dockerfile?

you can have multiple WORKDIR in same Dockerfile. If a relative path is provided, it will be relative to the previous WORKDIR instruction. If no WORKDIR is specified in the Dockerfile then the default path is / . The WORKDIR instruction can resolve environment variables previously set in Dockerfile using ENV.


1 Answers

The Dockerfile that ended up working was

FROM node
ADD . / frontend/
RUN (cd frontend/; npm install;)
CMD (cd frontend/; npm start;)

Shoutout to @Matt for the lead on . / ./, but I think the only reason that didn't work was because for some reason my application will only run when it is inside a directory, not in the 'root'. This might have something to do with @VonC's observation that the node image doesn't have a WORKDIR.

like image 98
iambicSam Avatar answered Oct 07 '22 19:10

iambicSam