Skip to content
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

Build on top of or extend another service #2773

Closed
CWSpear opened this issue Jan 28, 2016 · 4 comments
Closed

Build on top of or extend another service #2773

CWSpear opened this issue Jan 28, 2016 · 4 comments

Comments

@CWSpear
Copy link

CWSpear commented Jan 28, 2016

Is there a way to build an image based on another service, i.e. extend their Dockerfile?

For example, I have a PHP app that installs a bunch of deps on build and starts php-fpm on up called php, then a I have a separate container that runs migrations and clears caches, etc, called app. The thought is I can re-run app and keep php running to minimize downtime when I need to redeploy.

Currently, both images need all those deps, so I have to make sure those RUN directives in their Dockerfiles are mirrored, but ideally, I could build app on top of php and not have to do that. Is that currently possible or anything that others have interest in?

@dnephin
Copy link

dnephin commented Jan 28, 2016

The features has been discussed a few times (#295) also related is #1896

For your use case, I think you can use docker-compose run instead. run is designed to handle these adhoc tasks. For example: docker-compose run php ./some/migration/script

up is for running services which are long-lived, not for adhoc tasks.

@CWSpear
Copy link
Author

CWSpear commented Jan 28, 2016

Thanks for the response, but neither of those address the issue I'm trying to bring up. Maybe I'm not wording it right.

I basically want in my Dockerfile to FROM another service to extend the Dockerfile. The tickets you linked and the use-case you mention are for run-time dependencies. I'm talking about the build-time.

Basically a way to do docker build -t my-php ./php/ then I could FROM my-php in my app's Dockerfile. Is there a way to do that sort of thing in a more clean, elegant way in docker-compose? (I mean, I'm thinking not at this point, but would it be something people might be interested in?)

@dnephin
Copy link

dnephin commented Jan 28, 2016

Sorry, my understanding was that the reason you wanted the ordering was to solve another problem, so I addressed what I understood was the original problem.

For build ordering see: #295 (I did link this one), #1455 (for context on why we probably wont support it), #610, and #583 for related requests.

The rest of my comment was in response to:

For example, I have a PHP app that installs a bunch of deps on build and starts php-fpm on up called php, then a I have a separate container that runs migrations and clears caches, etc, called app. The thought is I can re-run app and keep php running to minimize downtime when I need to redeploy.

Currently, both images need all those deps, so I have to make sure those RUN directives in their Dockerfiles are mirrored, but ideally, I could build app on top of php and not have to do that

I'm suggesting that build ordering might not be the best way to solve it. You could instead have just a single service (not two services), and use run to run the adhoc tasks (migrate, cache clean), since it uses the same code, and presumably the same service dependencies.

@CWSpear
Copy link
Author

CWSpear commented Jan 28, 2016

Heh, it was my turn to not read carefully. #295 is indeed relevant.

Ok, so yeah, I understand. In thinking about this more, I did try breaking it out to two services and sharing files via volumes. I think we can close the issue as duplicate. I think the one that drives home what I was looking for is image_from (but still being able to adding to it with a Dockerfile... basically just prepending a FROM this-newly-build-image to the top).

Anyway, thanks for the replies. I'm going to go ahead and close as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants