Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to COPY/ADD file into current WORKDIR in Dockerfile

Tags:

COPY/ADD statement requires 2 parameters. How can I add any file to current workdir that has been set in base image?

FROM company/app
COPY local.conf

Sure I can add WORKDIR statement before COPY to explicitly declare it. But that would be problematic if the workdir in company/app changes.

like image 684
akhy Avatar asked Feb 25 '16 05:02

akhy


People also ask

What is ADD and COPY command in Dockerfile?

COPY COMMAND ADD COMMAND. COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image.

What is copy and Workdir in Dockerfile?

WORKDIR instruction is used to set the working directory for all the subsequent Dockerfile instructions. Some frequently used instructions in a Dockerfile are RUN, ADD, CMD, ENTRYPOINT, and COPY. If the WORKDIR is not manually created, it gets created automatically during the processing of the instructions.

What is add file in Dockerfile?

The ADD command is used to copy files/directories into a Docker image. It can copy data in three ways: Copy files from the local storage to a destination in the Docker image. Copy a tarball from the local storage and extract it automatically inside a destination in the Docker image.


1 Answers

It turns out to be very simple. I just need to use dot to copy to current workdir.

COPY local.conf .

Still cannot figure out if this has some gotchas. But it just work as intended.

like image 89
akhy Avatar answered Sep 25 '22 00:09

akhy