skip to Main Content

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)

2

Answers


  1. 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.

    Login or Signup to reply.
  2. You can use this command:
    docker-compose up -d --force-recreate --build main

    Reference

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search