Home > Blockchain >  Docker compose file invalid
Docker compose file invalid

Time:03-22

I'm new to docker and I've created a dockerfile but am having difficulties with my docker-compose file. I'm currently getting the error services.web.ports must be a list. I have a node app.js file that handles requests and prints data from database and an index.js file that looks like this

"use strict";
console.log("entrypoint");
const app = require("./app/app.js");

My Dockerfile looks like this:

FROM node:latest
WORKDIR /src
COPY package*.json /src/
RUN npm install
COPY . /src
EXPOSE 3000

And this is what my current docker-compose file looks like

version: '3.3'
services:
  app:
    build:
      context: ./
    volumes:
      - .:/src
    ports:
      -"3000:3000"
    depends_on:
      - db
  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: true
      MYSQL_DATABASE: world
      MYSQL_USER: root
      MYSQL_PASSWORD: null
    ports:
      - "3308:3306"
    volumes:
      - db:/var/lib/mysql

I wrote this based on an example, and I know it's faulty and would appreciate any guidance. If I were to run the app.js file alone via node it works fine but I'm trying to implement docker to my project and need help.

CodePudding user response:

The service for app has a typo in the ports section. A list is indented entries prefixed by a - . The line here is missing the space:

    ports:
      -"3000:3000"

Fix that by adding a space:

    ports:
      - "3000:3000"
  • Related