Answer the question
In order to leave comments, you need to log in
How to conveniently execute composer / npm / artisan / ... in Docker?
If before docker this was all done in the terminal using F12 and the node integration tab, by clicking on the npm command, how is it convenient to do it now?
PhpStorm has integration with Docker and there, by clicking on a running container, you can execute exec commands. I do exec bash in php and there, in a small and inconvenient terminal, I can already write composer or artisan. And this is how it should work now? Or is it done in some other way?
One more question. Am I doing the right thing by putting composer/git in the Dockerfile to php? Or do you need a separate container for the composer?
Answer the question
In order to leave comments, you need to log in
Through docker-compose I use the command in the terminal:
docker-compose run *container name* *command* (for example, php artisan)
You build the project in one container, there is a composer and other build tools
, and then you run it in another one, where there is only php and code.
If I understand correctly, the question is to conveniently perform repetitive operations inside docker containers.
I had a strain with the fact that you need to constantly connect inside containers and perform operations inside them. So I sketched out a simple composer plugin for myself.
Made for myself. If it seems interesting to someone and throw issues, then I'll do the finishing.
https://github.com/vladitot/composer-extra-plugin
Use multistage build, this is when you write the FROM directive 2 or more times, which will allow you to collect artifacts in 1 Dockerfile and not litter the final image.
If I understand correctly, you want to build locally in a container, and then test the application using it.
There are several paths, of varying degrees of difficulty and with different results. I think the easiest thing for you to do is to write a bash script that contains the whole sequence of composer calls and other things, and put the script inside the container at the build stage. Then, just call it via exec in phpstorm as needed.
Any script, strictly speaking, is also a process, just interrupted. Therefore, according to the covenant, it must run in a separate dying container.
If composer and artisan still somehow fit into the php container, then npm already somehow wants to be in a separate container. And it would be strange to separate approaches. Therefore, for each tool, start a separate dockerfile. This separation will also make it easier to update tools, although I suspect for many this is not so important.
In the dockercompose file for development, I leave the console for containers
...
python_server:
stdin_open: true
tty: true
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question