Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda