简体   繁体   中英

Docker running both Yarn update and npm update on docker-compose up

I am running a docker container that is containing my backend code as a volume:

docker-compose.yml

version: '3'

services:
  auth:
    container_name: ${AUTH_CONTAINER}
    build: ./modules/auth
    working_dir: /usr/app
    command: "npm install && npm start"
    volumes:
      - ../backend/modules/auth:/usr/app
    expose:
      - 9229
    ports:
      - 9229:9229

Dockerfile:

FROM node:alpine

WORKDIR /usr/app

COPY entrypoint.sh .

ENTRYPOINT ["sh", "/entrypoint.sh"]

Entrypoint:

#!/usr/bin/env bash
exec "$@"

when I run docker-compose up, the first step is always to run yarn. I get an error saying that I should not use both npm and yarn, because I currently am using npm for the project. Is there a way to have node:alpine only use npm only (I know its installed) and then call npm install when docker-compose up is ran?

EDIT: image of console: 控制台图像

EDIT2: Package.json

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}

For anyone that gets to this point- and is wondering why this is happening. Ensure that you run the docker-compose -- build FIRST before running docker-compose up that is the problem I was running into.

Dockerfile

FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY entrypoint.sh /

ENTRYPOINT ["sh", "/entrypoint.sh"]

entrypoint:

exec "$@"

docker-compose:

version: '3'

services:
  auth:
    container_name: "Auth"
    build: "./auth"
    working_dir: /usr/app
    command: "npm start"
    environment:
      - NODE_ENV=local
    volumes:
      - ../backend/modules/auth:/usr/app
    expose:
      - 9299
    ports:
      - 9229:9229

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM