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

208
Visualizações
Execute command on host during docker build

Is it possible to create Dockerfile that executes a command on host when image is being build?

Now I'm doing:

./script_that_creates_magic_file.sh
docker build .

with Dockerfile:

FROM alpine
COPY magic_file

I want to be able to do:

docker build .

with Dockerfile:

FROM alpine
# invoke script_that_creates_magic_file.sh on the host
COPY magic_file

Of course, this script is in the same directory as Dockerfile.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

(Just a suggestion)

We usually have the following structure for building our docker images:

my-image/
├── assets
│   ├── entrypoint.sh
│   └── install.sh
├── build.sh
├── Dockerfile
├── README.md
└── VERSION
  • build.sh: This is were you should invoke script_that_creates_magic_file.sh. Other common tasks involve downloading required files or temporarily copying ssh keys from the host. Finally, this script will call docker build .
  • Dockerfile: As usual, but depending on the number of commands we need to run we might have an install.sh
  • install.sh: This is copied and run inside the container, installs packages, removes unnecessary files, etc. Without being 100% sure - I think such an approach reduces the number of layers avoiding multiple commands in a single RUN
  • entrypoint.sh: Container's entrypoint. Allows us to perform tasks when the container starts (like parse environment variables) and print debugging info

I find the above structure convenient and self-documented since everyone in the team can build any image (no special instructions/steps). The README is there to explain what the image is doing... but I won't lie to you... it is usually empty... (or has an h1 for the gitlab to display) :)

about 4 years ago · Santiago Trujillo Relatório

0

To answer the question; no there is no built-in functionality to run a command on the host before docker build (i.e., no "hooks" to trigger scripts on the host).

If you provide more information about your use case, possibly there are alternatives (e.g. using a combination of --build-arg, and docker compose)

about 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