PHP development environment with docker (and how to use composer) - php

I play with docker for a while and I wanted to use this to build a PHP development environment.
With PHP I use composer.
Despite my research about using docker to build a devlopmenet environment, I essentially found sample code showing how to run an existing PHP app (but not how to make a development environment)
like : https://github.com/tutumcloud/tutum-docker-php
I don't really understand if I have to run composer inside the container or outside ?
Can you show me some examples where I have my source code in a directory on the host, shared with container via a docker volume and how to use composer with this setup ?
Thanks :)

interesting setup here :
geoffrey.io/a-php-development-environment-with-docker.html
available on github :
https://github.com/ubermuda/docker-symfony

Related

Laradock in remote containers with VS code and PHP IntelliSense working

How to setup "PHP IntelliSense" on Visual studio code with Laradock to use the PHP binary in the laradock_workspace_1 container?
I have tried to start Remote-containers: attach to running container..., then problem is I can´t access my git repo since its mounted on Windows.
In Windows I can´t access the PHP binary in the docker container, is it possible for vs code to access PHP some remote way(without open a new vs code in the container), so it will have all libraries and modules loaded. This is something I need to get PHP IntelliSense working in correct way? Now some of the autocomplete are not working for example all functions related to Eloquent.
I have found this but unfortunately I don´t understand how to get it work:
https://github.com/laradock/laradock/issues/2248
Any other suggestions on how to get autocomplete to work, without install same PHP version in Windows (I don´t want to pollute my system)?
Start with connecting to the Laradock workspace container (Remote-containers) and mount the folder:
/var/www/
This will allow you to access the files outside the container.
Then for PHP IntelliSense you should add this line to the settings file:
{
"php.executablePath": "/usr/local/bin/php"
}
It might be possible to export the port to php-fpm outside the container, but nothing I know how to do. You can also connect to the php-fpm container, but I think the workspace is more practical to connect to.

How do I maintain work inside drupal containers for working in teams?

I am new to Drupal and just looking for some help getting my dev environment going and using best practices.
So I have a working container with drupal, mariadb, drush etc... so after installing Drupal with the installer, I install themes and such however it seems if I drop the container I lose all my work. How could I ever work in a team then? How do I keep that work? Do I use git inside the container and pull and push from within?
As far as I'm aware, work inside the container does not necessarily reflect into my local working directory.
Any help would be much appreciated.
I dont know about dupral but generally in docker you would mount a folder from your local filesystem where docker is running when you start the container. The data in the "/your/local/folder" will be accessible both in the container and in your local filesystem. It'll also survive a restart of the container.
docker run -d \
-v </your/local/folder>:</folder in container>:z \
<your image>
The trick will be to identify the data in the container you want on your local filesystem.
Look here for different alternative ways to handle persistent data in docker:
https://docs.docker.com/storage/volumes/
I can highly recommend you Lando for Drupal 8.
SEE: https://docs.devwithlando.io/tutorials/drupal8.html
It's a free, open-source, cross-platform, local development environment and DevOps tool built on Docker container technology.

Is it possible to deploy a PHP remote git with Cloud Shell in Google cloud?

After reading several webs and google cloud documentation, I start thinking that is not possible to deploy a PHP git repo https://github.com/GoogleCloudPlatform/getting-started-php.git directly from Cloud shell.
In every tutorial, and in the documentation they always say you need the gcloud SDK to run it locally, but how about directly from Cloud shell?
The idea is to make work a PHP hello world example like the one in https://github.com/GoogleCloudPlatform/getting-started-php/tree/master/1-hello-world but I'm having problems with the runtime. Official tutorial
In env: flex, only the following runtimes are allowed:
('python-compat', 'java', 'java7', 'go', 'custom')
After reading I might be missing something related to docker file or composer.json, I did tests with this last one but without success so if there's a way it might be with docker file.
But while I continue investigating I wanted to know if it's possible and if I'm missing something.
Thank you!

How to run (or should I run) PHP composer on Jelastic?

Basically what I'm trying to do is to create a simple multi-node env with varnish+nginx+mariadb+memcached. By now I've managed to launch the environment and attach git project to it. The problem is that we work with php and symfony2, which requires composer to be executed at least once in order to properly deploy the application.
Outside of jelastic we use Jenkins + Ant (but we don't scale horizontally in automatic on the projects where this setup is used, so it's not a problem to add node manually).
So the question is: How can I run composer or ant with build.xml on each deploy?
I see that Java environments have a build server option, is there something like this for php environments?
PHP projects do not have a "standard" build server in the way that many Java projects do - requirements for PHP build tools are more varied depending on the particular project.
For example one customer may ask for grunt, another for ant, and another for phing.
If you want to perform a sophisticated build, you can create your own build node for your PHP project using an Elastic VPS or separate Docker environment. To deploy the built project to your servers you can use SSH connections, or simply git push and set the runtime environment to auto-update (e.g. via ZDT feature) from that git repo / branch.
If your needs are more simple, you can install composer directly onto your php runtime node in the normal way via SSH.
E.g.
$ curl -sS https://getcomposer.org/installer | php
There are more detailed tips about how to tidy that up (add to your PATH etc.) at http://kb.layershift.com/jelastic-install-composer

Replicating Heroku environment in Docker (or other container)

I would like to have a local development environment that is a clone of my Heroku environment, with same dependencies, etc.
I can develop locally on my OSX machine, but I use brew for package management, and it is a chore to keep all the versions the same as my heroku setup.
My issue is I don't like deploying to my Heroku development environment every time I make a change. It really slows down my development time, waiting for the slug to compile and deploy.
Is there a way to use Docker to mimic exactly whats in my Heroku stack? (PHP, Nginx, MongoDB ... ) Anybody done this or have a link to a tutorial?
Thanks
You might consider dokku. It uses Heroku buildpacks by default and you can add things like MongoDB instances with its plugin system (here's a dokku mongo plugin).

Categories