Closed ArtyMcFlyHA closed 3 years ago
Hi @ArtyMcFlyHA
The effects of the depends_on
key are clearly outlined in the documentation. As you can see, build ordering is not an intended usage of depends_on
. More generally, higher-level build automation is not an intended usage of Compose, and we recommend finding complementary tools to fulfill this usage (dobi is usually a good candidate)
Hi @shin-
Thanks for the quick response as well as the clarity you've provided! I will definitely look into dobi, thank you for the recommendation! :)
I will say though, I believe as written at the time of this issue creation, we see the documentation painting different pictures. IMHO, it does not clearly outline that build ordering is not an intended usage. https://docs.docker.com/compose/compose-file/#depends_on the "simple example" even includes a service that has a build context.
I realize documentation is a separate issue, but I'd advise that "simple example" have it's build context removed and There are several things to be aware of when using depends_on
have the case of docker-compose build
be added to it.
I'm not alone in thinking this should've worked, I tracked down a couple posts on other internet forums on the topic where other devs also believe that depends_on
would dictate build order. I'm going to link your response to said third party forums.
This solution can help
There is nothing in the docs about what the effects of depends_on
are in the context of docker build
. The way it's written, docker build
is not even mentioned - to me it's not immediately clear if this is an omission, or a lack of support.
Further, docker build
does respect depends_on
while docker build <service>
does not. Maybe it's a "feature" of docker build
, or maybe docker build <service>
has a bug. Nothing is mentioned one way or the other.
The effects of the
depends_on
key are clearly outlined in the documentation. As you can see, build ordering is not an intended usage ofdepends_on
. More generally, higher-level build automation is not an intended usage of Compose, and we recommend finding complementary tools to fulfill this usage (dobi is usually a good candidate)
@shin- Is dobi still recommended? I see that dobi has not received commits since July. I am trying to evaluate what tool to use because we have outgrown docker-compose build.
I am here because like others I feel the documentation is lacking. I spent a couple hours because of this simple example on https://docs.docker.com/compose/compose-file/
version: "3.7"
services:
web:
build: .
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres
There are no comments that lead me to believe that the behavior is anything but
Wow! So build
won't build the services in which it depends_on
like up
. That's a bit of a suprise. Good to know. I'm glad I found this thread.
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.
This issue has been automatically closed because it had not recent activity during the stale period.
Hi, I'd like to re-open this issue as I think having a way to prioritize docker builds would be very helpful.
Sometimes we have a docker-compose file where we build several images. One "core" (nginx for example) and others that will extend it by adding some specific configurations (php for example). When doing so, one has to be built before others. For quite some time (several years) docker-compose build
was respecting that order. Suddenly when switching to parallel builds it does not anymore. I understand it wasn't the intend at first but has been widely used... Would it be possible to consider it again ?
Thanks.
I think it is now possible to prioritize builds correctly using the buildx bake
command, as of buildx 0.8.x. See the "Create Build Pipelines by Linking bake Targets" section in this blog post: https://www.docker.com/blog/dockerfiles-now-support-multiple-build-contexts/
This does not seem to be supported in compose syntax, it is necessary to use the json/hcl bake syntax instead.
Description of the issue
docker-compose build <service-name>
does not appear to followdepends_on
likedocker-compose up -d <service-name>
. Note, this is different than https://github.com/docker/compose/issues/5228 which has a similar wording, but the linked issue does not usedepends_on
in the docker-compose.yml file.Context information (for bug reports)
The Dockerfiles in question:
Output of
docker-compose version
Output of
docker version
Output of
docker-compose config
(Make sure to add the relevant-f
and other flags)Steps to reproduce the issue
docker system prune -a
(to ensure no local images cached)docker-compose build nodejs
Observed result
nodejs
is attempted to be built without attempting to buildalpine
first and an error occurs as a result. (stacktrace below)Expected result
I expected
alpine
to build first,nodejs
to build second. Ifdocker-compose up -d nodejs
is run instead ofdocker-compose build nodejs
than alpine is built first as expected. I am expecting the following output:Stacktrace / full error message
Additional information
macOS High Sierra version 10.13.6
Note,
docker-compose build
appears to work as expected (though that may be due to alphabetical ordering of service names?). However, the above is a boiled down least code replication of the issue. A more practical example of where this issue becomes a problem is when there are several dozen services and only 1 or 2 need to explicitly have their images/dependencies built.Also note, I replaced the private registry domain I'm using with
my-private-registry
. If you use a made up repository, the error will readService 'nodejs' failed to build: pull access denied for my-private-registry/alpine, repository does not exist or may require 'docker login'
instead of... failed to build: ... not found
. That said, expected output should be the same as above.