N
N
No2021-03-02 22:30:54
MongoDB
No, 2021-03-02 22:30:54

How to configure networks and volumes in docker?

Good evening, I'm trying to run a nodejs application and a mongodb database in docker. An error occurs on startup:

$ docker-compose up --build -d

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.networks: 'app-network'
Unsupported config option for services.volumes: 'dbdata'


I looked at the documentation and googled, but did not find the answer. Docker Version: 20.10.3

Dockerfile:
FROM node:14.16.0-alpine3.10
RUN mkdir -p /app/node_modules && chown -R node:node /app
WORKDIR /app
COPY package*.json .
USER node
RUN npm install
COPY --chown=node:node . .
CMD [ "npm", "start" ]


docker-compose.yml
version: "3.8"

services: 
  node-app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: node-app
    ports:
      - "80:80"
    env_file: .env
    networks: 
      - app-network
  mongodb:
    image: mongo:4.1.8-xenial
    container_name: mongodb
    env_file: .env
    environment:
     - MONGO_INITDB_ROOT_USERNAME=$MONGO_USERNAME
     - MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASSWORD
    volumes: 
     - dbdata:/data/db 
    networks: 
     - app-network 

  networks: 
    app-network: 
  volumes: 
    dbdata:


.env
MONDO_PROTOCOL="mongodb"
MONGO_USERNAME="some_name"
MONGO_PASSWORD="some_password"
MONGO_HOSTNAME="127.0.0.1"
MONGO_PORT="27017"
MONGO_DB="test"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
No, 2021-03-02
@Ppechenka

Perhaps the error was in the indents. networksand volumesshould be on the same level services.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question