If you haven’t asked yourself yet or if you don’t read docs as many others, what would happen if you specify both
build as part of a Docker Compose file, here’s the catch.
- Docker Compose
When you define a service with both
build directives, the
image directive takes priority over the
build directive. This means that if you specify an image for a service, Docker Compose will attempt to pull that image from a registry, and the build context and instructions will be ignored.
However, if image pulling fails, building the image would be the next thing which will result having an image build with the tag specified from the
image: directive value.
In case of running
docker compose build followed by
docker compose up will result in overriding the image pulling operation from a remote repo with building the image based on the
build directive with the
image: value tag and
docker compose up will use that newly built image to start the Docker Compose stack.
If you don’t want to build anything just use the
In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.