I'm new to docker. How can I start a node service via docker-compose, which then accepts npm commands?

docker-compose up -d --build   <-- I use this command to start

I want the npm install to be executed and then I can enter e.g. npm mix or npm gulp or node -v or npm install node-sass --save-dev in the container. The package.json should be saved on my local machine (if i use npm install xyz).

my Dockerfile

FROM node:14-alpine
WORKDIR /var/www/html 
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install
COPY . .

my docker-compose.yml

    build: ./
    stdin_open: true
    tty: true
      - ./:/app
  • 1
    These should be part of your Dockerfile, not run adhoc because the changes done to the container will be lost when the container is destroyed – Sathyajith Bhat Feb 2 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.