Open asiragusa opened 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
As a workaround you can create a new service that will be responsible for building the image, and other services will use this image by name.
services:
my-app-image:
build:
context: .
dockerfile: Dockerfile
image: ${COMPOSE_PROJECT_NAME}-my-app
command: ['echo', 'The docker image (${COMPOSE_PROJECT_NAME}-docparser) is ready to be used.']
develop:
watch:
- path: ./requirements.txt
action: rebuild
my-app-instance-1:
depends_on:
my-app-image:
condition: service_completed_successfully
required: false
environment:
INSTANCE_NAME: instance1
build:
context: .
dockerfile: Dockerfile
image: ${COMPOSE_PROJECT_NAME}-my-app
ports:
- "3001:3001"
command: [ 'flask', 'run', '--host=0.0.0.0', '--port=3001' ]
my-app-instance-2:
depends_on:
my-app-image:
condition: service_completed_successfully
required: false
image: ${COMPOSE_PROJECT_NAME}-my-app
environment:
INSTANCE_NAME: instance2
ports:
- "3002:3002"
command: [ 'flask', 'run', '--host=0.0.0.0', '--port=3002' ]
Inspiration: https://stackoverflow.com/questions/40899236/how-to-prevent-docker-compose-building-the-same-image-multiple-times
But after that you can't use sync
action in services until the issue is resolved: https://github.com/docker/compose/issues/12065
This issue has been automatically marked as not stale anymore due to the recent activity.
This was happening on containers that are supposed to exit. A workaround that worked for me for those containers was to prevent the container from exiting.
command: ["sh", "-c", "bin/generate && tail -f /dev/null"]
However, when sending a SIGINT
signal to kill the docker
process, these containers no longer shutdown gracefully — they time out shutdown after 10 seconds.
Description
Docker compose watch builds multiple time the sources even if two or more services share the same build configuration. In my case I have 10+ services that use the same Dockerfile in a mono repo and this slows down significantly the build process.
Moreover if one of the rebuild targets is changed while
docker compose watch
is not running, the build is not triggered at the start.Steps To Reproduce
A simplified version of my docker-compose.yaml below:
Compose Version
Docker Environment
Anything else?
No response