I am creating a console-based app in Node JS. No ports are being used... It's just a basic app. The problem I am having is using Docker to run my app.
Here's my docker file:
FROM node:16
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "node", "index.js" ]
After building the image, I try to run 'docker run ' and the container just exits right away. However, when i use the Docker desktop app, after building the image, if I click 'run' it builds the container and does not exit, but actually runs. When I log into that container, I am able to run 'node index.js' and my node app runs fine.
My question is, why does it work when using the GUI docker run and not my command? Also, why do I have to run 'node index.js' manually when the docker file should take care of that?
Commands to build image and run the container:
Image build:
docker build -t 'appname' .
Create container:
docker run 'appname'