[Vuejs]-How can i run vue3 "npm run dev" in docker?

0👍

The single biggest thing causing you immediate trouble is this Compose override:

# delete this line
entrypoint: /bin/bash

This tries to run an interactive shell instead of your dev server; but since Compose runs background services, this shell exits immediately and you can’t interact with it at all.

More generally, you have far too many Compose options, and a couple of them are dangerous (notably, you’re replacing node:lts with your custom image). I’d reduce the Compose file to just

version: "3.8"
services:
  vue:
    build: .
    ports:
      - 3000:3000
    volumes: # (probably delete this too)
      - ./:/var/www/html/app
    env_file:
      - ./.env
  nginx:
    image: nginx:1.15
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 80:80
      - 443:443

For all of the others, either Compose or your Dockerfile provides reasonable defaults. As I hint in a comment, I’d also typically delete the volumes: block, so that you’re using the code built into the image and not replacing it with something else; this does conflict with your desire to simulate a local development environment using an isolated container.

(And correspondingly, I think the actual easiest thing to do here is to run npm run dev directly on your host system, without Docker; it doesn’t seem like what you show here particularly benefits from being isolated in a container.)

Leave a comment