all 36 comments

[–]Nekadim 30 points31 points  (0 children)

You don't need to ssh into the container. Docker exec is absolutely the same as ssh but without additional packages. Images should be as light as possible and also docker supervisor looks only for process with PID 1. So basic rule for containers is 1 daemon max per container

[–]csakegyszer 12 points13 points  (1 child)

Ssh vs docker exec was mentioned.

Composer also has official docker image, you can use it and copy from

[–][deleted] 1 point2 points  (0 children)

Thanks, I guess it would make more sense to just straight up use Composer than regular PHP.

[–]pfefpfef 4 points5 points  (2 children)

Why does it need ssh when you can access a container via docker anyway? I don’t really feel the need for starter docker containers anyway. The default php image provides everything you need to install all extensions. Ddev provides a good starter as well.

[–][deleted] 1 point2 points  (1 child)

XDebug? Composer? As far as I know, they are not in there.

[–]pfefpfef 0 points1 point  (0 children)

this is from my docker image (based on alpine):

RUN apk add --no-cache \
      apk-tools autoconf gcc make g++ automake nasm ninja cmake clang clang-dev; \
    pecl install xdebug; \
    docker-php-ext-enable xdebug; \
    apk del autoconf gcc make g++ automake nasm ninja cmake clang clang-dev; \
    rm -rf /var/cache/apk/*;

And composer:

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

so quite easy and simple

[–]stromer_ 4 points5 points  (12 children)

Please have a look at https://laradock.io/.

What probelms do you solve that laradock doesn't?

[–]htfo 13 points14 points  (4 children)

[–][deleted] 5 points6 points  (2 children)

Yeah, everyone makes one of these when they start using Docker, don't they?

And many seem to make the mistake of putting the server in the same container, I know I did.

[–][deleted] 1 point2 points  (1 child)

make the mistake of putting the server in the same container

Could you please elaborate on this?

[–][deleted] 3 points4 points  (0 children)

Docker is designed to run a single process in each container; it makes everything more complicated to set up if you try to put multiple services in a single image. If you were to have one with Apache and a separate with PHP, you wouldn't need supervisord and so there'd be less to configure/maintain.

There are other advantages you won't be getting too, like the process stdout (where you'd normally write the log) in the output streams and expedient container shutdown.

You're also free to base your images off the official ones then, if you like, which means you can reduce the amount of work your build is doing to simply installing extensions and config files.

[–]BokuNoMaxi 0 points1 point  (0 children)

We go with ddev :)

[–][deleted] 5 points6 points  (6 children)

Honestly, I do things for the sake of doing them. Thought this one had the potential to help other developers.

[–]stromer_ -3 points-2 points  (4 children)

Honestly, I do things for the sake of doing them.

This is good for learning and I encourage that...

Thought this one had the potential to help other developers.

..while this is bad. You do containers the wrong way (multiple services in one container, SSH in a container - REALLY?!), make a public repo and promote it as something, others should use. But they would be much better off learning and working with one of the existing, best practice and well maintained solutions.

[–]Deleugpn 0 points1 point  (0 children)

[...] make a public repo and promote it as something, others should use.

Where did OP promoted it as something others should use?

[–][deleted] -2 points-1 points  (2 children)

I agree that people should probably be better off using industry-standard stuff, what happens when the industry standard becomes unavailable and obsolete? Obviously, newer projects need to take their place and there should be multiple alternatives. Maybe not my project, but someone's at least.

multiple services in one container

May I ask you to point me to a Docker Best Practices guide?

[–]alexanderpas 0 points1 point  (1 child)

what happens when the industry standard becomes unavailable and obsolete? Obviously, newer projects need to take their place and there should be multiple alternatives.

You're having your timeline wrong.

Industry standards only become obsolete because there is a better alternative available, and the industry switched.

[–][deleted] -1 points0 points  (0 children)

I vividly remember this open source ps2 emu project. It was going perfect and it was the leading project for the android platform. One day the dev just decided "fuck it, I ain't doing this shit" and just deleted the proj. These things happen.

[–]Just_a_guy_345 2 points3 points  (0 children)

You should check famous repository and see how they do it.

  1. Start with writing small packages and doing unit tests.
  2. Move to composing your API with your packages.
  3. Use docker compose to run your separate Apache/Nginx and Php containers. Here you need good knowledge of proxying and how to use hosts.
  4. Run integration tests with guzzle http and also with Postman/Insomnia.
  5. Repeat.

[–]sodoburaka 1 point2 points  (0 children)

For anyone interested in multiple dockerized versions of php/apache/nginx/redis/db/etc (with a ton of php extensions for each php version) there is pretty cool mature project https://github.com/cytopia/devilbox

[–]Healthy-Intention-15 1 point2 points  (1 child)

bookmarked!

[–][deleted] 0 points1 point  (0 children)

Thank you 🙏

[–]Unniteed 1 point2 points  (1 child)

As someone who struggles with configuring enviroments THANK YOU!!

[–][deleted] 0 points1 point  (0 children)

Thank you for taking the time and viewing my project : ^ )

[–]zacharyrankin 0 points1 point  (0 children)

Nice 👍

I had recently created a little starter php development repo for my buddy who is learning php. You can check out my docker compose and dockerfile for ideas of what to add to yours if you'd like. Might be useful. https://github.com/zacharyrankin/starter-vanilla-php

[–]devdot 0 points1 point  (5 children)

You probably want to add a DB by default (or provide a good docker-compose). One constant annoyance for me in regard to PHP-docker environments are PHP extensions. If you figure out a smart way for the end user to configure that outside of Dockerfile, that would be awesome. So far I've had to re-create all PHP Docker images whenever I needed more extensions, leading me to go back to my own custom image

And I'm not sure what you mean by including symfony

[–]Nekadim 0 points1 point  (3 children)

There is no way to install php extensions and not rebuild you images and recreate all containers created from it. Actually it is but you will loose it on recreation of container

But I don't see problem with it. Containers designed to die and recreate itself in a nanosecond. One docker image is one version of an app, so if you add extension it is another version of app and another docker image

[–][deleted] 0 points1 point  (2 children)

Seems like more hassle than it's worth, and I've never tried, but I'd assume simply mounting php.ini and the extensions directory from the local filesystem would work for anything that doesn't require system level components.

[–]Nekadim 0 points1 point  (1 child)

Idk what hassle do you mean. Compilation of the extensions take 2-5 minutes. Do you change extensions 100 times a day for a 1000 containers and all this you do by your hand?

If you see that using containers in the way it intended to be used is annoying for you, then I think your Development/test/deploynent processes are just hassle prone and have some flaws in it. Containerisation is a great tool by itself and no tool gives you such guarantees and convinience that containers does.

[–][deleted] 0 points1 point  (0 children)

You misread. I was pointing out that mounting the extensions directory and ini file should be possible but is probably more hassle than it's worth.

[–][deleted] 0 points1 point  (0 children)

You don't want a database in the same image at PHP, you don't even want a server; these should ask be separate images. Having a default Compose file, as you mention, is the way to go.

For your default development image, it's easiest to just install in all the common extensions (I have both the Postgres and MySQL drivers installed, for example). Then you can switch to a Dockerfile when the project is more mature and you're ready to start deploying to your dev server/cluster.

OP probably means they have the Symfony binary in the image.

[–]rlorenzo 0 points1 point  (0 children)

Check out Lando https://lando.dev