-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't build the same thing twice #963
Comments
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
Duplicate of #610? |
+1 |
+1 |
+1 |
1 similar comment
+1 |
I'm trying to use compose to launch multiple containers from the same image but with a different command. Running Right now, my workaround is to build and tag the image separately, and then reference it from the compose configuration file. I think this could be addressed in compose if there was a way to reference built images within the |
As of Compose 1.6.0 you can use both |
Thanks, just saw this on the documentation: https://github.com/docker/compose/blob/master/docs/compose-file.md#build It definitely solves the problem for me. |
This solves most of the problem, still, when building images in a shared context(e.g.: a CI server), the images would end having the same name and would override each other. This isn't an issue as we can just change the project name, changing the prefix of all created objects. The problem is that if you use This can be solved either by exposing by some way the project prefix or if the image from one service could be referenced from other project. The first one can be addressed with a simple shell script but I think that docker-compose should handle this natively, preferably with the second option, as it solves side effects like |
@etcinit The link to the doc doesn't work anymore. Can you share how you solved your problem? |
Here is the current link for docker-compose file reference build |
What about using partial images? Generate an image with all common factors and build on top of it. This may also be resolved together with #1896, though I believe we actually need actually more decoupling of building and running (Only-build/partial images, which would allow devs to use "FROM" to build on top of it), while also allowing for granular control during run-time, which in the end could amount to 2 separate, albeit somewhat related, issues. Depends a lot on the design. My suggestion would be for the Compose-File to allow two new keys, |
@frnco I agree that greater decoupling between building and running is needed. frankly, if all I specify is a |
Perhaps I am not understanding the solution proposed by @dnephin. I have a compose file like:
And yet, when I run EDIT: I can only reproduce this using Docker for Mac, so it does not seem to be compose related. |
@mrname I accomplished this by omitting version: "3"
service:
web:
build: .
…
sidekiq:
image: myproject_web:latest
… What @dnephin described with your Compose file would be |
@jbhannah omitting |
just write a separate docker-compose file specially for build
|
I recommend using Procfile with overmind / hivemind / foreman |
+1 |
1 similar comment
+1 |
I would prefer a solution that is more natural: when two services define the same context and docker file it should automatically use the same image - the image name could be the first service defined the docker file or To be honest: I don't think someone will work on a 4 year old issue. My hope in the docker community is long gone. |
@tflori I feel the same. I gave up on Docker a while back and have been building serverless on Now |
I've managed this issue in the following way: version: "3"
services:
build:
image: single_image_app
build:
context: .
dockerfile: test-Dockerfile
svc1:
image: single_image_app
depends_on:
- build
svc2:
image: single_image_app
depends_on:
- build |
Both docker-compose in latest releases and Compose V2 use BuildKit as a builder backend, and this one manage building images in parallel with deduplication for equivalent Dockerfiles in compose services. |
The solution with a separate build service doesn't work for me. It doesn't seem like docker ever tries to wait for the dependent services. If stackoverflow is true, then depends_on only makes sure that the dependent services will run after their dependencies: |
Yes indeed, depends_on was not designed to apply at build time. There a more general issue here with Dockerfiles which depend on another service image as base image. Still no fix yet |
doesn't work now =( |
I'm on |
Even though Docker caches layers and the second build is fast, it's not necessary for Compose to build the same thing twice. As far as I can tell, if two services in the yaml have exactly the same string, you can be sure they will be exactly the same build:
Naturally, the image built is the same for both services.
There's also the question of the race condition if someone edits the Dockerfile while fig is already building. This is a bit contrived, but does work:
Contrived or not, if it didn't attempt to run the same build twice, it wouldn't have divergent images.
The text was updated successfully, but these errors were encountered: