简体   繁体   中英

docker-compose NPM container keeps restarting

I am trying to create a container that is just running cli scripts. At the moment I do not have the scripts written I'm just trying to get the container started first. The following set up creates the container fine, but it keeps restarting and after spending hours trying to find a solution on line I've not got any closer to a solution:

DockerFile

FROM node:18-alpine
WORKDIR /src
COPY package*.json /
EXPOSE 3000

RUN npm install -g nodemon && npm install
COPY . /

docker-compose.yml

version: '3.8'
services:
  calculations-script:
    restart: unless-stopped
    build:
      context: .
      dockerfile: DockerFile
    command: npm run dev
    volumes:
      - ./:/src
    ports:
      - "3000:3000"

package.json

{
  "name": "test-nodejs-script",
  "version": "1.0.0",
  "description": "Test script",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "node index.js"
  },
  "author": "Testing",
  "license": "ISC"
}

You container is restarting because of the restart field in your manifest which is set at unless-stopped . unless-stopped ensure that container is always restarted unless manually stopped.

What you probably want is no or on-failure , docs for more details

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