-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Image inheritance #610
Comments
Inspired by "inherits"; perhaps "extends" is another alternative. |
I strongly suspect this should be a Docker-level concern, not Fig's realm. See the discussion here: moby/moby#735 |
hm, yes, if multiple images should be built using However, if I understand correctly (I may be on the wrong foot here), the idea here is to re-use the image that was built for a service in another service, i.e.
Basically, this should work already if the correct image-name is referred to (but haven't tested it), but may fail if the services are started in the incorrect order. The inherit part is not really part of the original proposal/feature request, and (again, if I understand correctly), is meant to copy the settings of another service (as specified in fig.yml), and override only those settings that are different. This request should probably be move to another issue (imo) |
Cleaned up my comments. |
OK. I can see the value in something like an However, I don't think inheriting other configuration is a good idea - shared portable configuration should instead be moved into the Dockerfile. As for non-portable configuration like volumes and ports:
|
Tested working! :) I will attempt to create a patch / pull request. BTW - Love the build system for fig - using a docker image to build - genius! Here is the output using my code changes fig.yml extract (phpfrpm inherits volumes_from and links from php)
fig build
(technically we wouldn't need to run the 2nd build command on this occasion as it ends up with same container - but if there were build differences it would be different) fig up -d
fig ps
|
Test2: Maybe 'EXTENDS' is a better name for the option? fig.yml
fig build
fig up -d
fig ps
docker ps
fig logs serviceC
fig stop
fig rm
|
You can accomplish this with yaml anchors and aliases: serviceA: &serviceA
image: ubuntu:14.04
volumes:
- /serviceA:/serviceA
environment:
PROJECT: services
SERVICE: serviceA
command: /bin/sh -c "while true; do echo $PROJECT; echo $SERVICE; echo ServiceA $(date) > /serviceA/date; sleep 1; done"
serviceB: &serviceB
<< : *serviceA
volumes:
- /serviceB:/serviceB
environment:
SERVICE: serviceB
command: /bin/sh -c "while true; do echo $PROJECT; echo $SERVICE; echo $(cat /serviceA/date); echo ServiceB $(date) > /serviceB/date; sleep 1; done"
serviceC:
<< : *serviceB
command: /bin/sh -c "while true; do echo $PROJECT; echo $SERVICE; echo $(cat /serviceA/date); echo $(cat /serviceB/date); sleep 1; done" |
I thought the best way to show the code would be via a pull request https://github.com/docker/fig/pull/625/files As you can see, it's very simple |
It is relatively short, but I still think this can be accomplished directly from yaml. |
Would that still work? |
I believe you'd have to: serviceB: &serviceB
<< : *serviceA
ports: [] While it may seem inconvenient to have to override things with an empty list, at least that way it's explicit. Otherwise the options which are copied or not copies are hidden in fig, and requires a lot more documentation for users to understand. |
Wouldn't the documentation explaining how to use YAML be more though? Rather than For users, wouldn't it better to have built-in support rather than needing to know YAML? The main point of fig is to make setting up docker images easier isn't it? |
Also, having it built-in to fig gives some useful feedback if you typed something wrong What happens if you do the YAML wrong? |
I just think if there's a way to encourage more services more easily, it will stop people being tempted to do: phpService: |
I agree that if it's possible using pure YAML it should not be an option added in fig. But we should add an example in the doc explaining how to do that using YAML. |
The case where I'd like to use this is when I have a worker and web app running from the same code base. Currently using yaml inheritance I will end up with two images being built which is a waste of space and time. What if there was a statement to web: &app
build: .
command: bundle exec unicorn_rails
environment:
RAILS_ENV: development
REDIS_URL: redis://redis/0
DATABASE_URL: postgres://postgres/dev
worker:
<<: *app
use: web
command: bundle exec sidekiq |
You need 2x docker "instances" anyway. The 2nd image will be the same, so will just use the cache of the first. All FIG does is read config files and then run the Docker commands for you in the background. Your generated commands would be something like docker run ae368852 bundle exec unicorn_rails ae368852 = is just a random container ID So, using the same container, but just creating 2x "instances" of it. |
@matthuisman You can in fact start start two different containers from on the same image, so I'm not quite sure what you mean. As well as basing a fig service image on a local Dockerfile or an image from a registry, what I'm suggesting is allowing the direct use of another local service image, cut the overhead. Instead of this:
I want this:
|
I believe this was address with |
@dnephin Doesn't it still end up different images only difference being the last commit? I might be wrong. |
The image tags are different, but the layers should all be the same. If this is just about re-using the same image, I think that's covered by #963 |
#625
I have a base image that I use for PHP (PHP-CLI & PHP-FPM)
Would be cool if you could tell fig to inherit a previous image as a base.
The child image would then have all the attributes of the parent, and then you would be able to override the parents attributes / add attributes.
It is simply generating a different Docker Run command based on the parents command.
No extra building / pulling etc would be needed.
Current Method
Proposed Method
Behind the scenes
This will help reduce code duplication and make it easy to modify attributes just in the parent image.
Say my PHP images now required another service (MYSQL), I would simply need to add the mysql link to the first image.
At present, I would need to duplicate this change to all the other images which could lead to broken images if one is missed.
What would need deciding is what attributes get inherited, what attributes overwrite the parents and what attributed append to the parents.
Volumes - Append?
Environment variables - Append?
Ports - Don't inherit?
The text was updated successfully, but these errors were encountered: