T
T
texttotext2018-06-28 07:23:16
PHP
texttotext, 2018-06-28 07:23:16

How to properly develop a php application in docker?

There is an application in php. Several developers are working on it. The code is in the gitlab repository. Now each developer has his own virtual machine, nginx, postgres, php-fpm are installed there. Developers upload code via sftp. All this works well. But there are a lot of microservices and some kind of automation of application launch is needed.
Now I want to transfer everything to docker. We have built an image based on php7-fpm. It is necessary that the container contains the code from the master branch and is automatically assembled into this branch during the merge. We will configure this via gitlab ci.
Here we have a container with code inside, in order to run it, you need to register the configs in the .env file and run it using docker-compose. Everything is working.
But how is the developer to develop now? Let's say he changed the index.php file, how can I put the changed file into the docker container now? Here I see 2 options:

  1. volume folder. Those. the folder with the application code is rummaged between the host machine (the host machine will be the developers' virtual machine)
  2. Connect via ssh to the container and upload via sftp

The first point has several disadvantages:
  1. volume folder inside the container is created as root. The application code must and runs as a normal user.
  2. If this folder exists in the container, then it is deleted and created from scratch. Those. if we share the folder with the code, then the code will simply be deleted

In ENTRYPOINT in the Dockerfile, you can put a bash script file in which you can manipulate folders.
At the second point I do not know problems yet.
Once again, the question is: how to upload code changes during development to a programmer in a running container?
It is desirable to resolve the issue so that the programmer does not take a steam bath with docker building.
How do you solve it?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
index0h, 2018-06-28
@index0h

Separate the concepts of DEV container and PROD container.
The DEV image does not contain your project's code, it only contains the environment, and the code is mounted via volume. The engineer makes changes locally, sftp is not required.
PROD container contains a specific version of the code with everything and dependencies, it is only launched to work in conjunction with DEV containers.
For example, you have services: sa, sb, sc.
In docker-compose.yml you write 6 services: sa_dev, sa_prod, sb_dev, sb_prod, sc_dev, sc_prod.
Pairs *_dev and *_prod live on the same ip with the same DNS aliases, this is necessary in order to provide a hard connection between your services and not overwrite half of docker-compose.yml
For example, you want to edit sb, but sa and sc are used by sb. You raise:
sa_prod, sb_dev, sc_prod.
Make your edits and check. When everything is ok - commit edits and build a new sb_prod image, push it to the register and update the version in docker-compose.yml

L
LightAir, 2018-06-28
@LightAir

A new developer is coming.
Installs the required software (git, docker, docker-compose, storm, composer, etc.).
Gets data from the git. In the git, there is a docker-compose.yml file with the necessary settings, which indicates which folders from the host where to mount in the composer.json scripts section of the command, such as 'd:build', 'd:start', in which everything is written for deployment and start containers.
The developer runs a couple of commands like 'composer run-script d:build && composer run-script d:start'.
Ready.
Then it works according to the agreed git flow.
The same can be done with Vagrant, it doesn't matter.

I
Igor Yatsevich, 2018-07-09
@IgoNsk

Here is my report at the conference on this topic
https://2018.codefest.ru/lecture/1260/
Maybe something will be useful from there.

A
abr_habr, 2018-06-29
@abr_habr

We took the first path. I just remade the php-fpm image, adding to it in docker-entrypoint the creation of a user who owns the mounted folder. Plus, php-fpm itself inside the container is now also launched from this user.
The advantage of this approach is that I added xdebug to the custom image, which is not in the original distribution.

A
Anton Anton, 2018-06-28
@Fragster

Well, if you have git, then let the programmer push to the master, and the docker takes the image and rebuilds it. What is point 1, what is point 2 in the presence of a gita is nonsense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question