Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deromanenko's avatar

Node in docker for assets building: npm run dev not working

Hello! I created a docker compose configuration to serve my application. (I know about Sail, but I wanted to make basic configuration by myself to learn Docker better)

I add node as container:

  node:
    container_name: node
    image: node:lts
    working_dir: /var/www
    volumes:
      - ./:/var/www
	ports:
	  - 5173:5173

And added tailwind to my assets. But I can't get npm run dev to working. I start it like that:

docker compose run --rm node npm run dev

Vite sees file changes and reload it

3:15:52 PM [vite] page reload resources/views/welcome.blade.php (x2)

But it has no effect on my assets when I change tailwind classes in the *.blade.php files. Like there is no Tailwind at all. npm run build works as expected.

There are errors in console:

GET http://127.0.0.1:5173/@vite/client net::ERR_CONNECTION_REFUSED
GET http://127.0.0.1:5173/resources/css/app.css net::ERR_CONNECTION_REFUSED

It seems that I should somehow expose vite from node container to application, but how do I do it?

Thank you

0 likes
7 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Check if it is exposed by running docker ps

Personally I expose the port, start the container with docker compose, and finally uses docker-compose exec to run the command in the running container

1 like
deromanenko's avatar

@Sinnbeck no, it was not exposed. In fact, node container exited right after starting :)

I think I need to start this container with "npm run dev" as entrypoint or something (I started to learn Docker yesterday)

deromanenko's avatar

Yahoo, it works with this configuration:

  node:
    container_name: node
    image: node:lts
    working_dir: /var/www
    volumes:
      - ./:/var/www
    ports:
      - 5173:5173
    entrypoint: ['npm', 'run', 'dev'] # To start building

Thank you very much @sinnbeck

1 like

Please or to participate in this conversation.