Closed Voziv closed 2 years ago
Yes, ideally prod doesn't have any dev-only dependencies. There are several major ways to do this, of which none are yet implemented in this repo (but I would love PR's)
image:
command)There are lots of pros and cons to each of these as well as likely other options. Many are hidden in the nuance of how your team develops, tests, and deploys software so it's hard to capture it all in a few bullet points, but in general:
As I work on these containers for my work I'll look into making PRs with my discoveries!
I'm currently using multi-stage builds in a Symfony project. I got my inspiration from Sylius-Standard. I know these guys are serious about best practices. What I did was a first parent php stage, followed by two separate test and dev php stages (I'm not using Docker in prod, yet).
from php:7.2 as php-base
# build the base image. Put all common parts here.
# …
from php-base as php-test
# COPY sources and stuff
# …
from php-base as php-dev
# install xdebug
# bind mount sources, etc.
There's one hiccup with those multi-stage builds, though: apparently, there's no way of telling Docker NOT to build a stage if you don't need it in a specific environment.
@vctls The "skip building a stage if not needed" was not a feature of the original docker build
. That's now built into BuildKit and the new docker buildx
in the upcoming 19.03 release.
Hello!
First off I want to thank you for the awesome work you've been doing with these "good-defaults" repos. They've been immensely insightful.
I have a few questions about creating a production image.
Would it make sense to have development dependencies omitted for the production build? Currelty I added
--prefer-dist
and--no-dev
to composer to exclude the dev libraries and download .zip files instead of cloning repos.What would be sane to install the
xdebug
extension only in development?I'll try to update this issue as I find out more information. Any insight you may be able to provide as well is greatly appreciated!