Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker compose file invalid

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading