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
You can easily do that as a shell command:
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.
You can use this command:
docker-compose up -d --force-recreate --build main
Reference