by Devin Yang
(This article was automatically translated.)

Published - 4 years ago ( Updated - 4 years ago )


When developing Laravel, sometimes we need to install the nodejs package through npm, but Node in our system is not new enough.
It may be impossible to upgrade due to some factors, such as running an old version of nodejs program, etc.
In fact, we can use docker through simple commands, so that we can use the latest version of node image to mount the /sites folder on the host side.
In this way, we can execute the new version of the npm command at any time.

docker command

When we are in the folder of dlaravel, execute the following command:
docker run --rm -v ${PWD}/sites:/sites -w /sites -ti node bash

For example using the LTS version:
docker run --rm -v ${PWD}/sites:/sites -ti node:8.11.4 node npm -v

Let me explain them one by one:
run:    to execute a new container. (Run a command in a new container)
--rm:  Automatically remove the container when it stops.  (Automatically remove the container when it exits)
-v:      Bind mount a volume. (Bind mount a volume)
          This means that the data of the sites folder on the host side will be seen in the /sites folder in the container.
-w:     The default working directory is set to /sites here, so that after we enter the container, it will be in the /sites folder, which is D-Laravel's Projects Folder.
-t:       Allocate a pseudo-TTY
-i:       Keep STDIN open even if not attached
node: is the image we want to use.
bash: We want to execute the instructions in the container.

In other words, after executing the above command, we can enter the container.

You can enter ls to view the directory of the project.
Enter the Laravel Project directory,
You can easily npm install or npm run dev.

D-Laravel command (version 1.6.6)

Confirm the D-Laravel version.
./console version
D-Laravel release v1.6.6

way of entry
./console node

It's simpler, and when you use ./console alias to set it as an alias, it is equally effective and can be executed in any directory.


Tags: docker laravel

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories

laravel teaching, blade

Tags on my Laravel blade

Using Laravel's Blade Templates is quite easy to use, and I'm used to it after a long time, but one thing is that when a lot of blades are created, it seems that it is not easy to find myself. Here is my latest original method. If it is the same Pure coincidence.


Ran out of Docker IPv4 address pool problem solving

Maybe in the old version of the docker environment, when using Docker compose to start the container, you will encounter the following error: Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network This is actually this It is a symptom of running out of default-address-pools. In some environments, docker-compose will use the private network of Class B by default. The private IP of segment 172 has a range, from to That is to say, when we start a docker-compose Project, it will eat a private section of Class B, which is very heroic.

laravel storage

How do I sync files with Laravel's Storage's sftp driver

The installation and setting of SFTP is beyond the scope of this article. If you want to know more, I suggest you read another article In this article, I will use a very fast Sample. Demo How do I use the self-built artisan command to synchronize the remote data to the local end. Some people may ask why rsync is not used. This article is to introduce the use of Storage to synchronize files. 🤪Let’s look directly at the code, I set up an sftp disk called ccc in config/filesystems.php.