L
L
l4m3r2019-02-17 03:02:00
phpstorm
l4m3r, 2019-02-17 03:02:00

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

7 answer(s)
G
gupovski, 2019-02-17
@gupovski

Through docker-compose I use the command in the terminal:
docker-compose run *container name* *command* (for example, php artisan)

O
OnYourLips, 2019-02-18
@OnYourLips

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.

V
vladitot, 2019-02-19
@vladitot

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

M
metajiji, 2019-02-17
@metajiji

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.

D
Dmitry Shitskov, 2019-02-18
@Zarom

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.

E
Egor Mokeev, 2019-02-18
@zetamen

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.

E
Eugene Pedya, 2019-02-21
@fpinger

In the dockercompose file for development, I leave the console for containers

...
python_server:
        stdin_open: true
        tty: true
        ...

Then I connect to the running container
And do what I need in it. For example, I launch and put my script. And so on.
At the same time I correct the code outside.
In a docker compose for publishing, the excess is removed and the code is placed in a container.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question