Home > Back-end >  How to rebuild one single container and start all services with docker compose
How to rebuild one single container and start all services with docker compose

Time:09-29

I am using docker v20.10.18 and am trying to run two services through a docker-compose.yml file, one that is simply pulled from another registry, and another that I wish to rebuild quite regularly

# docker-compose.yml
version: "3"
services:
  inference:
      image: registry.example.com/image:latest
  main:
    build:
      context: .
      dockerfile: Dockerfile

When I need to rebuild the image my main, I do it via docker compose build main.

Then I can run both services with simply docker compose up.

I was wondering if there was a way to turn these two commands into a single one.

I have docker compose up --build main, but main is the only container that starts (after indeed being rebuilt)

CodePudding user response:

You can easily do that as a shell command:

docker compose build main && docker compose up

With the && you ensure that the 2nd command doesn't run if the 1st one fails. This is (not exactly, but similar to) how I do it.

CodePudding user response:

You can use this command: docker-compose up -d --force-recreate --build main

Reference

  • Related