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

155
Visualizações
Can docker compose skip build if the image is present?

Is it possible to run docker-compose up in such a way that it will only build if the image isn't present in the repository?

I'm working on a test scenario that will run in two different environments: locally on a laptop, and on a server as part of test automation. My docker-compose file looks something like this:

services:
  my-service1:
    build: "./local-repo1"
    image: "image1"
  my-service2:
    build: "./local-repo2"
    image: "image2"
  ...

If I run it locally where the local-repo directories exist it runs fine. If I try to run it on the server where it instead pulls from a docker repository it complains that it cannot find the build path. If I take out the build property it runs fine on the server, but then it won't run locally unless I build the images beforehand.

Is there a way to make it only try to build if the image doesn't already exist? If not I can try some workarounds, but I'd prefer to use just one docker-compose file that handles each case.

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

0

You can use docker-compose pull to fetch images. Then if they are present already, Compose will not try to build them again.

To be really sure to avoid rebuilds, you can use --no-build.

docker-compose pull
docker-compose up -d --no-build

Your real problem is that you are specifying a build context, but then trying to use docker-compose without that build context being present.

When docker-compose runs, even if it has no plan to do a build, it will verify the build context at least exists. If it doesn't, then it will fail.

All you need to do to satisfy this requirement is create an empty directory for any missing build context. That should make docker-compose happy enough to run.

mkdir -p local-repo1 local-repo2
over 4 years ago · Santiago Trujillo Relatório

0

i am using docker-compose v2.1

when we run docker compose up it check image is exist or not. if not exist then only it build that image otherwise it will skip that part

docker-compose

version: '2.1'

services:
  devimage:
    image: nodedockertest
    build: .
    environment:
      NODE_ENV: development
    ports:
      - 8000:8000

enter image description here

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