我正在尝试使用angular(tailwind)和docker,但每当我尝试访问localhost:4200时,我总是得到err_empty_response

nukf8bse  于 2023-04-05  发布在  Docker
关注(0)|答案(1)|浏览(167)

下面是dockerfile docker-compose and package.json我最关心的是路径,我已经尝试添加CMD [“npm”,“start”,--host0.0.0.0]并没有工作,可能是什么问题?
这里是dockerfile

# pull official base image
FROM node:14
ENV PATH=$PATH:app/node_modules/.bin
#app/
# set working directory
WORKDIR /app

# install app dependencies
COPY package.json ./
COPY package-lock.json ./

RUN npm install

# add app
#COPY . .

# start app
EXPOSE 4200

CMD ["npm","start"]

和docker组成

version: "3.7"
services:
  app:
    container_name: template
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "4200:4200"
    volumes:
      - ./:/app

package.json文件的一部分 *

"name": "notus-angular",
  "version": "1.1.0",
  "description": "Notus Angular - Free Tailwind CSS UI Kit and Admin by Creative Tim.",
  "repository": "https://github.com/creativetimofficial/notus-angular",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --poll 1000 ",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:tailwind": "tailwind build src/assets/styles/index.css -o src/assets/styles/tailwind.css",
    "install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm run build:tailwind && npm start"
  },

我怀疑smthg的路径或node_modules位置有误

m528fe3b

m528fe3b1#

我最近创建了一个Angular 开发环境。我的docker文件:

FROM node:lts-alpine as builder
COPY . /app
WORKDIR /app
RUN npm install
RUN npm install -g @angular/cli
CMD ["ng","serve","--host","0.0.0.0"]

还有我的作曲

version: '3.8'

services:
  angular_devel:
    image: angular:1.0.0
    container_name: angular_devel
    hostname: angular_devel
    ports: 
      - "4200:4200"
    volumes: 
      - "./angular_devel/node_modules:/app/node_modules"
      - "./angular_devel:/app"
    restart: always
    networks: 
      - main
      - database

networks: 
  main:
    driver: bridge
  database:
    driver: bridge

在我的compose文件中,我Map了两个卷。但后来我意识到第一行是多余的。我的一些docker.ignore / git ignore以某种方式排除了node_modules....希望它能有所帮助。

相关问题