I am learning docker by following an online course and have successfully built an image with my Dockerfile but afterwards it is not creating and running the container; It does not say "Successfully built <CONTAINER_ID>" like in the course.
I thought my image should automatically create and run a container as specified by the last step: CMD ["npm","run","dev"]
Before docker, I would start my node app with "npm run dev" in the terminal and as you can see in my package.json script below, my dev command uses nodemon to run the file from src/index.js.
I am wondering if this is still the correct path to run index.js from with Docker because the Dockerfile step WORKDIR '/app'?? I tried changing the dev script to run from "/app/src/index.js -e js" because of the command WORKDIR '/app' as well but no difference???
Any idea on why my created image is not creating a running container after being built?
Thank you!
Dockerfile
FROM node:14-alpine
WORKDIR '/app'
COPY package.json .
RUN apk update
RUN apk add --no-cache python3 py3-pip
RUN npm install [email protected]
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
package.json scripts for CMD to run
"scripts": {
"dev": "env-cmd -f ./config/dev.env nodemon src/index.js -e js",
"prod": "env-cmd -f ./config/prod.env nodemon src/index.js",
},
OUTPUT from "docker build ."
Why isn't it running a container from CMD ["npm", "run", "dev"]???
[ ] Building 5.5s (14/14) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 504B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:14-alpine 0.6s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [1/8] FROM docker.io/library/node:14-alpine@sha256:4af...........4d66779 0.0s
=> [internal] load build context 0.9s
=> => transferring context: 1.85MB 0.9s
=> CACHED [2/8] WORKDIR /app 0.0s
=> CACHED [3/8] COPY package.json . 0.0s
=> CACHED [4/8] RUN apk update 0.0s
=> CACHED [5/8] RUN apk add --no-cache python3 py3-pip 0.0s
=> CACHED [6/8] RUN npm install [email protected] 0.0s
=> CACHED [7/8] RUN npm install 0.0s
=> [8/8] COPY . . 2.5s
=> exporting to image 1.4s
=> => exporting layers 1.4s
=> => writing image sha256:9738.......5d80b4316a8 0.0s
CodePudding user response:
Are you sure that the files are copied correctly?
You set the workdir, but I suggest to copy artifacts like this:
COPY . /app