8000 Docker support · Issue #54 · symfony/flex · GitHub
[go: up one dir, main page]

Skip to content

Docker support #54

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

Closed
dunglas opened this issue Apr 28, 2017 · 21 comments
Closed

Docker support #54

dunglas opened this issue Apr 28, 2017 · 21 comments

Comments

@dunglas
Copy link
Member
dunglas commented Apr 28, 2017

Hi,

I've created an alternative Symfony skeleton with Docker support: https://github.com/dunglas/symfony-docker-skeleton
It's basically the API Platform Docker setup tuned to support Flex.

It works, but some minimal modifications can be done to some recipes to ease the install (expect some PRs soon).

Main differences with the standard skeleton are:

  • It doesn't use the Dotenv component (Docker has a builtin support of .env files)
  • In dev mode, the front controller can be accessed from the host

It's probably possible to go one step further and to automatically add required services with a Configurator (e.g: add a Redis image to docker-compose.yml when installing predis/predis).

Is it something you may include into Flex?

@fabpot
Copy link
Member
fabpot commented Apr 28, 2017

That's very interesting and definitely a scenario that should work with Flex. I would really like if we could have automatic configuration based on what packages you install (like your Redis example). Not sure we have the right abstractions for that right now, but happy to add anything that would help going in that direction. I wanted to be able to do the same for SensioCloud. So, that would benefit more than just Docker.

The only thing we need to think of is the override of the web/index.php file.

In any case, please continue working on this, that gets me very excited.

@dkarlovi
Copy link
dkarlovi commented May 2, 2017

I have a rather complex Symfony app (WIP, also ApiPlatform) in Docker: development with Docker Compose, deployment to Openshift / Kubernetes, support for environments, a lot of tweaks per each image for example, my app image allows for XDebug on development but it's disabled on production (using the exact same image, different runtime environment) or uses the same image for web app server (PHP-FPM) and async CLI-workers (Console + Enqueue bundle) which, if in development, monitor the src/ folder for changes and auto-restart the workers.

From that experience, it shouldn't be too hard to get a pretty good all-around config, but the problem would be how to allow for extendability as you currently can't extend Dockerfiles (you can extend Docker Compose file, that's how I get the per-environment settings), it would be a run-once deal.

@teohhanhui
Copy link

I don't believe Symfony Flex should create services in the Docker Compose file (or its equivalent in other container orchestration systems).

But we really need a "developer story" to understand what's the experience like using Symfony Flex with Docker. I believe that for Symfony Flex to be successful, it really needs to treat Docker as a first-class citizen (and this is the perfect opportunity to ensure that is the case). I've just started trying it out...

@andrerom
Copy link
andrerom commented Jul 12, 2017

First, @dkarlovi nice work on https://github.com/dkarlovi/symfony-flex-docker, healthcheck and all.

As for extensibility there are a few things we can potentially use here:

  • Recipes can be allowed to specify either php extensions to enable (among the once in php source), or to install via pecl
    • (One blocker here, pecl is not able to pick latests version of for instance memcached on PHP 5.6, you'll have to specify version for that. Not saying we care about php 5.6, but the same issue will come back at any point there is sufficient breaks in php again for extensions)
  • Recipes can provide own services, we can use docker composes support for being able to stack several files after each other (also supported by COMPOSE_FILE env variable that can be set in .env)
    • This is not without down sides, makes running the thing more complex, but for example see, and
  • Makefile with abstraction / simplification for docker use
  • Symfony Flex generating .env file for the result, including COMPOSE_FILE, and providing build arguments to app container for php extensions

@dunglas
Copy link
Member Author
dunglas commented Jul 12, 2017

@andrerom I'll open a PR on Flex soon adding the ability to update docker-compose.yaml and the Dockerfile from a recipe.

I've also created a new installer for Flex using Docker: https://github.com/dunglas/symfony-docker-skeleton/tree/autoinstall

@teohhanhui
Copy link

the ability to update docker-compose.yaml and the Dockerfile from a recipe.

As long as it is strictly opt-in only.

@dkarlovi
Copy link

@andrerom

First, @dkarlovi nice work on https://github.com/dkarlovi/symfony-flex-docker

Thanks,

I'm thinking more in line of:

  1. creating a utility which is able to emit a valid Dockerfile while being configured programmatically
  2. setup the base symfony-flex-docker repo to allow for placing configuration for 1) in with a classic .d notation
  3. split the base repo into sub-repos which would add their specific fragments into those .d folders (this would allow say symfony-flex-docker-mysql to request the app image to support pdo_mysql, for example, or similar)
  4. rebuilding the base Dockerfile and the base app image when required

It seems like it would go a long way.

@dkarlovi
Copy link

the ability to update docker-compose.yaml and the Dockerfile from a recipe

Also not a fan of this, TBH.

@joelwurtz
Copy link

the ability to update docker-compose.yaml and the Dockerfile from a recipe

Not a fan either as i think docker-compose is a too higher level of abstraction for that.

IMO we should build something that use directly the Docker API so it will be easier to maintain and also we would have more capabilites and better integration with Docker.

@dkarlovi
Copy link

use directly the Docker API

This is a wrong level of abstraction, IMO. You'd need to figure out how to hook into stuff like Kubernetes / OpenShift / other solutions which already do this so you end up between a rock and a hard place. While, using Compose, you get to use more established tools like Kompose.

@dunglas
Copy link
Member Author
dunglas commented Jul 20, 2017

My prototype is almost working. Please wait for it and the related blog post to make an opinion.

Kubernetes support is a must have (it will come). But Docker-compose is shipped with most Docker installations. It will allow to manage the lyfecycle of a Symfony project from installation to production and during all the development cycle.

In term of DX, it will be a game changer, and definitely better than Vagrant, Homestead and other WAMP.

@Aerendir
Copy link

@dunglas , did you publish the blog post you cited in your comment? Where is it? I'd like to read it to understand better Docker use with Symfony other than the code in the repo you are working on... Thank you!

@teohhanhui
Copy link

The closest thing for now is https://github.com/api-platform/api-platform

@covex-nn
Copy link
Contributor

@dunglas i have some questions =)

How do you recommend to start new project? via download dunglas/symfony-docker and docker-compose up or via traditional composer create-project symfony/skeleton? How do you think recommended Dockerfile and docker-compose.yaml should be delivered to developer? How do you deploy your projects to production? Do you build docker image with project code? Do you use same docker-compose.yaml in dev and prod?

@dunglas
Copy link
Member Author
dunglas commented May 28, 2018

Hi,

How do you recommend to start new project?

Using download dunglas/symfony-docker and docker-compose up, but this repository deserves an update (it works, but can be improved thanks to recent changes in both Flex and Docker)

How do you think recommended Dockerfile and docker-compose.yaml should be delivered to developer?

What do you mean exactly? See #128 for the state of the art (nothing ready yet)

How do you deploy your projects to production?

Using Kubernetes.

Do you build docker image with project code?

I'm not sure of what you mean exactly, but I guess the answer is yes.

Do you use same docker-compose.yaml in dev and prod?

I use Kubernetes in dev, not Swarm.

@covex-nn
Copy link
Contributor

What do you mean exactly?

If you recommend to start new project with downloading a repository, then initial recommended Dockerfile and docker-compose.yaml will be downloaded together with that repository (and Dockerfile will have its ###> recipes ###); and #128 is about how to update that initial files. I think a starting point, i.e. how developer creates a new project, is very important. And if i understood you correctly, you suggest to replace composer create-project with something different.

About building an image with project code: you use build feature to describe and launch services, not image, so i guess you do not build images with code to launch them in production. And php from container with application reads files from the host via ./:/srv/app:rw volume. This is important for me too.

Thank you for your answers, @dunglas

@teohhanhui
Copy link

@covex-nn I'd suggest adapting from https://github.com/api-platform/api-platform as it's the most up-to-date setup we have.

@covex-nn
Copy link
Contributor
covex-nn commented May 29, 2018

@teohhanhui i am looking for a workflow that start from creating a project and developing with docker-compose and finish on building docker images and deploying them to production (my own solution is not perfect =)

I would like to have a standard "workflow from Symfony", which most of developers will use without modifications, and with which i could:

  • Start a project with composer create-project symfony/skeleton;
  • Copy docker specific files into project, develop symfony app in a team, debug scripts with xdebug;
  • Build images, push them to docker repository, and deploy to staging/production;

From api-platform i potentially could take Dockerfile, but there is no installed xdebug in there. And unfortuntely i cannot manage Alpine Linux (i switched to base image, based on debian:stretch-slim)

@akomm
Copy link
akomm commented Feb 12, 2019

@fabpot
the flex recipe for FrameworkBundle would already be more docker friendly, if it would stop forcing on you using either .env.local.php or DotEnv. See: symfony/recipes#529

If it instead would check for already existing APP_ENV and do simply nothing, otherwise fall back to one of the above. But it does not. Instead it expect from you do provide it an FAKE environment in one of two different ways. When you have a clean user per app setup with environment OR docker, this is bad, because your app has a false environment, which in reality does not (have to) exist in the context the app is run. Yout forcefully detach the app environment from its real environment. This way, you do not need environment and can simply name it "configuration variables". The issue though is, that just replacing the new bootstrap and ditching DotEnv (sad I had to do it) does not fix the issue of you forcing the multi-env-file logic on the user. I need to either completely drop using flex OR to "fake" the .dist logic from before making my .env.local the .env, which naming wise kind of is less clear and common practice.

@dunglas
Copy link
Member Author
dunglas commented Feb 12, 2019

While I agree, this does the trick with no real drawbacks: https://github.com/api-platform/api-platform/blob/master/api/Dockerfile#L71

@akomm
Copy link
akomm commented Feb 12, 2019

@dunglas but why workaround, instead of simple & clean solution? (symfony/recipes#529)

@fabpot fabpot closed this as completed Jun 26, 2019
tgalopin pushed a commit to tgalopin/flex that referenced this issue Dec 3, 2020
…stok)

This PR was merged into the master branch.

Discussion
----------

[FrameworkBundle] improve Makefile serve target

Related to symfony#49, I don't know if this the best way to do it. But as the Makefile is composed I don't think it's possible to use advanced Makefile features 😟

@greg0ire suggested something like this:

```makefile
.PHONY: serve

CONSOLE=bin/console

$(CONSOLE):
    @echo 'Woops! The console does not exist'
    @EXIT

serve: bin/console
    bin/console list server|grep server:start
    bin/console server:start
```

But don't know if you can have multiple targets with the same name but different conditions?

Commits
-------

7a7de4b [FrameworkBundle] improve Makefile serve target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants
0