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

[Proposal] Recommend using multi-stage build to use composer #22

Closed
stof opened this issue Aug 30, 2017 · 8 comments
Closed

[Proposal] Recommend using multi-stage build to use composer #22

stof opened this issue Aug 30, 2017 · 8 comments

Comments

@stof
Copy link

stof commented Aug 30, 2017

See https://medium.com/@othillo/adding-composer-to-php-docker-images-using-multi-stage-builds-2a10967ae6c1 for the explanation about this feature.

A common issue with people using this image is that they run composer inside the container generated by this image, which may have different platform packages than their actual runtime. Here are some issues they may face:

  • the install fails if they are missing extensions in the composer image (while they are available in their runtime image, which is where the code will be used)
  • the install does not fail for missing extensions in the runtime image (for extensions being part of the container image), leading to broken runtime
  • the update selects packages for the wrong platform, leading people to stop relying on platform requirements in composer updates (and then asking package maintainers to treat a bump of the min PHP version as a BC break requiring a major version)
@alcohol
Copy link
Member

alcohol commented Aug 30, 2017

Just to clarify, you're suggesting to add this to the readme/docs that are presented on the Docker hub?

@stof
Copy link
Author

stof commented Aug 30, 2017

There is one drawback though: Composer needs the Zip extension at runtime, and may need VCS tools (if you install from source). When using a multi-stage builds, these are needed in your own image.

@stof
Copy link
Author

stof commented Aug 30, 2017

@alcohol yes, this proposal is about documentation

@alcohol
Copy link
Member

alcohol commented Aug 30, 2017

Alright, I'm in favor of documenting this 👍 .

But indeed, word of caution should also be added regarding possibly required tooling/extensions.

@alcohol
Copy link
Member

alcohol commented Aug 30, 2017

Docs can be adjusted by forking https://github.com/docker-library/docs and then changing the files inside the composer directory. Not sure if just anyone can fork and submit though, or if I have to submit it from my fork.

@t3easy
Copy link
Contributor

t3easy commented Sep 12, 2017

The multistage build can be used to build the app inside the composer container and copy over the app to the final image. The new --chown flag for COPY (docker 17.09) will take care of the permissions. (Changing permissions in the final image would lead to an additional layer with the size of all changed files).
This way you don't need any vcs tools inside the final image.

@stof
Copy link
Author

stof commented Sep 12, 2017

@t3easy but you have the same drawback than the current usage of a separate container to use Composer: platform packages are based on the PHP runtime added in the composer image, not on your actual PHP runtime, impacting the dependency resolution.
Plus, your solution works only if you use composer only at build time (which is not the case when you want to run composer update or composer require btw). for development tools, you need to be able to have a shell with composer available (which is the case with the current approach using a composer container, and also when copying composer to your own container)

@alcohol
Copy link
Member

alcohol commented Sep 26, 2017

Does docker-library/docs#1017 suffice for now?

@alcohol alcohol closed this as completed Oct 17, 2017
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

3 participants