0

I'm trying to go through this part 2 of Docker's tutorial.

Here is my issue:

After creating successfully an image for the app, I try the command line (sudo) docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0 which should run a container and allow me to access the app at localhost:8000.

But when checking out docker ps, nothing, so I used docker ps -a to find back my container, and find it with STATUS Exited (1). Then I try docker logs bb to find out more, and get this:

npm ERR! missing script: start.

This is more than surprising, knowing that it comes from the docs, I don't know what to do next. If anybody has any clue, it would be really nice. Thank you in advance

1
  • Can you post the dockerfile you are using? Is it exactly the same as in the tutorial? Commented Oct 25, 2020 at 15:32

3 Answers 3

1

The error message means that npm can't find a package.json file which includes a script named start. So make sure that your package.json contains a script named start! Might already be the issue.

// Simple package.json example that contains a script with name test.
{
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
    },
}

When you look at the tutorial's dockerfile:

This makes sure that the commands are executed in a specific folder, e.g. copying files:

# Set the working directory.
WORKDIR /usr/src/app

This makes sure that the package.json file is copied into the workdir:

# Copy the file from your host to your current location.
COPY package.json .

Here it defines that npm start will be executed when you run the container:

# Run the specified command within the container.
CMD [ "npm", "start" ]

To further investigate I would execute the following command to start the container:

docker run -it -d <container-id> /bin/sh

Then go to the workdir and check if the app can be started manually:

# Go to workdir
cd /usr/src/app
# Here check if the package.json is part of the directory.
ls
# Manually run npm script
npm start
1
  • 2
    See my post below. What is really surprising is that it worked to use npm start from the bash, (maybe it's a problem with the version of npm I got in the image of node : FROM node:current-slim? I'm not sure to understand everything here...) However, wouldn't it be a good idea to send comments to the Docker's team on github or whatever, to avoid others to run into the same issue, by asking them to change the last line to CMD [ "node", "server.js" ]? Commented Oct 25, 2020 at 15:57
1

It worked to add these lines to package.json

  "scripts": {
  "start": "node server.js"
}

and the remake a new image etc...

2
  • Did you find out the issue because of my answer? If so please accept it for future reference. Commented Oct 25, 2020 at 15:52
  • No I read your answer just after successfully connected to my app on my browser! soz :P Commented Oct 25, 2020 at 16:02
0

I ran to the same issue, but the missing script this time is "debug" there is no note in the package.json about this script only this:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

however the docker-compose.dev.yml contains this command: npm run debug apparently the npm that I am using is a bit different, because this is the file generated by $npm init -y command.

$npm --version
6.14.4 
$node --version 
v10.19.0
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.