Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
What directory does a Docker build start in?

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).

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda