Using MySQL with node but can't get node app running

I am creating an API. I have the node code locally and the MySQL container from docker. I have tried setting up Docker Compose with the two services but, while MySQL runs just fine, the node app doesn’t work.
I have researched the issue and tried changing my Dockerfile on the node app, deleting my package-json file and running docker compose up -d --build but it still displays this message when running docker compose up

node_app | /bin/sh: 1: [node,: not found

The node app is using sequelize to connect to the DB.

Here is my Dockerfile

FROM node:20

COPY package.json /app/
COPY src /app/
COPY dist /app/

WORKDIR /app

RUN npm install

EXPOSE 3000

CMD ["node", "./dist/index.js"];

My docker-compose.yml

services:
  node_app:
    container_name: node_app
    build: .
    working_dir: /app/dist
    ports:
      - "9000:3000"
    environment:
      - MYSQL_DB=shopper-test-db
      - MYSQL_USER=emerson
      - MYSQL_PASSWORD=root
      - MYSQL_HOST=node_db
    restart: always
    depends_on:
      - node_db

  node_db:
    container_name: node_db
    image: mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_DATABASE=shopper-test-db
      - MYSQL_ROOT_PASSWORD=root

I am using typescript with node, so the src folder is where the TS files are stores and dist stores the JS conversions

Dockerfile looks ok, we use this:

FROM node:18-alpine

# set context
EXPOSE 3001
ENV NODE_ENV production
WORKDIR /home/node/app

# install dependencies
COPY package*.json ./
RUN npm install
#RUN npm audit fix

# add source to container
COPY dist ./

# run server
CMD [ "node", "server.js" ]

Remove the semicolon at the end of the CMD instruction. It is not a valid json with that character and your CMD will be handled as a string. And if you look at it that way, ["node is indeed not an existing command.

2 Likes