I have a Dockerfile that has, amongst other directives, the following:
FROM node:alpine
RUN cd /tmp && \
# several lines downloading/installing packages from zips
...
ADD src/config.json /myapp/config.json
WORKDIR /myapp
This is intended to be run from the root of the application repository to build the docker container. The RUN
command is placed early because it's getting the application dependencies and this logically should occur early in the process. (It is also chaining a bunch of commands together in order to keep the number of layers low.) However, the ADD
command expects to be in the same location as the Dockerfile - the root of the repository.
Given that, is there a way to 'remember' where the docker build started from, and use this to orient the ADD
? (Specifically, running this in a local dev environment will have a different whereami
when building than my build server.) Or am I stuck with interleaving these commands, first copying the configuration over, then downloading dependencies, and so on?
When I build, I am doing this from the root directory of my project (that contains a src
folder):
docker build -t myapp:dev .
The error I get is:
lstat src/config.json: no such file or directory
If I insert RUN pwd
the docker build reports it as being /
, but I don't know if this is what it considers it's 'context' (that is, any ADD
commands are relative to the pwd
).
In a default installation, layers are stored in C:\ProgramData\docker and split across the "image" and "windowsfilter" directories. You can change where the layers are stored using the docker-root configuration, as demonstrated in the Docker Engine on Windows documentation.
Build with PATH , and so all the files in the local directory get tar d and sent to the Docker daemon. The PATH specifies where to find the files for the “context” of the build on the Docker daemon.
By default, Docker stores most of its data inside the /var/lib/docker directory on Linux systems.
The docker build
command has one required parameter, a path to the context to send over to the docker engine for performing the build. This path is typically a single .
, making the resulting command look like docker build -t myimage:latest .
. All of the ADD
and COPY
commands pull in files from that context, in the above example, the current directory where you ran the docker build
command would be used. For the server and each user that runs your docker build
commands, they just need to pass the working directory that they have on their local machine.
The only other thing you can do to alter the ADD
and COPY
command behavior is to change the WORKDIR
which defines the relative path for commands inside your container, but does not affect where files are pulled from the context you sent with your build command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With