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

1.6K
Visualizações
How to rebuild and update a container without downtime with docker-compose?

I enjoy a lot using docker-compose.

Eg. on my server, when I want to update my app with minor changes, I only need to git pull origin master && docker-compose restart, works perfectly.

But sometimes, I need to rebuild (eg. I added an npm dependency, need to run npm install again).

In this case, I do docker-compose build --no-cache && docker-compose restart.

I would expect this to :

  • create a new instance of my container
  • stop the existing container (after the newer has finished building)
  • start the new one
  • optionally remove the old one, but this could be done manually

But in practice it seems to restart the former one again.

Is it the expected behavior?

How can I handle a rebuild and start the new one after it is built?

Maybe I missed a specific command? Or would it make sense to have it?

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

0

from the manual docker-compose restart

If you make changes to your docker-compose.yml configuration these changes will not be reflected after running this command.

you should be able to do

$docker-compose up -d --no-deps --build <service_name>

The --no-deps will not start linked services.

over 4 years ago · Santiago Trujillo Relatório

0

The problem is that restart will restart your current containers, which is not what you want.

As an example, I just did this

  • change the docker file for one of the images
  • call docker-compose build to build the images
  • call docker-compose down1 and docker-compose up
    • docker-compose restart will NOT work here
    • using docker-compose start instead also does not work

To be honest, i'm not completly sure you need to do a down first, but that should be easy to check.1 The bottomline is that you need to call up. You will see the containers of unchanged images restarting, but for the changed image you'll see recreating.

The advantage of this over just calling up --build is that you can see the building-process first before you restart.

1: from the comments; down is not needed, you can just call up --build. Down has some "down"-sides, including possible being destructive to your (volume-)data.

over 4 years ago · Santiago Trujillo Relatório

0

Use the --build flag to the up command, along with the -d flag to run your containers in the background:

docker-compose up -d --build

This will rebuild all images defined in your compose file, then restart any containers whose images have changed.

-d assumes that you don't want to keep everything running in your shell foreground. This makes it act more like restart, but it's not required.

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