- Learn Docker:Fundamentals of Docker 19.x
- Gabriel N. Schenker
- 198字
- 2025-04-04 13:21:30
Assembling the sources
In this step, we make sure all source files and other artifacts needed to successfully build the application are part of the image. Here, we mainly use the two keywords of the Dockerfile: COPY and ADD. Initially, the structure of the source inside the image should look exactly the same as on the host, to avoid any build problems. Ideally, you would have a single COPY command that copies all of the root project folder from the host into the image. The corresponding Dockerfile snippet could then look as simple as this:
WORKDIR /app
COPY . .
As mentioned earlier, you can also use the ADD keyword to download sources and other artifacts into the Docker image that are not located in the build context but somewhere reachable by a URI, as shown here:
ADD http://example.com/foobar ./
This would create a foobar folder in the image's working folder and copy all the contents from the URI.