Answer the question
In order to leave comments, you need to log in
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:
Answer the question
In order to leave comments, you need to log in
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
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.
Here is my report at the conference on this topic
https://2018.codefest.ru/lecture/1260/
Maybe something will be useful from there.
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.
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 questionAsk a Question
731 491 924 answers to any question