Dmytro Oleksyuk
Dmytro Oleksyuk

Reputation: 21

docker-compose up; ERROR: 'network_mode' and 'networks' cannot be combined

After rebuild .jar file, and rebuild docker image, i try to docker-compose up, then i have error ERROR: 'network_mode' and 'networks' cannot be combined

This is docker-compose.yml file

version: "3"
services:


  postgres:
    image: postgres:latest
    restart: always
    container_name: postgresdb
    ports:
      - 5432:5432
    environment:
      - POSTGRES_PASSWORD=admin
      - POSTGRES_USER=postgres
      - POSTGRES_DB=postgres
    volumes:
      - ./tables.sql:/docker-entrypoint-initdb.d/shema.sql
    networks:
      - rent-manager-network


  rent-service-manager:
    image: rent-service-manager
    network_mode: bridge
    container_name: rent-manager-app
    ports:
      - 8080:8080
    environment:
      SPRING_DATASOURCE_URL: ${POSTGRESS_URL}
    restart: always
    depends_on:
      - postgres
    networks:
      - rent-manager-network

networks:
  rent-manager-network:
    driver: bridge

Dockerfile:

FROM openjdk:11.0.1-slim as builder

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar

RUN java -Djarmode=layertools -jar application.jar extract

ENTRYPOINT ["java", "-jar", "application.jar"]

Upvotes: 1

Views: 6534

Answers (2)

Elijah M
Elijah M

Reputation: 835

From the docs on network_mode:

When [network mode is] set, the networks attribute is not allowed and Compose rejects any Compose file containing both attributes.

Further, networks: must be set to one of the following:

  • none
  • host (Gives the container raw access to the host's network interface)
  • service:{name}
  • container:{name}

Upvotes: 0

Søren Hansen
Søren Hansen

Reputation: 256

Please remove network_mode: bridge from the rent-service-manager service.

You don't need it when your network is bridged.

Upvotes: 1

Related Questions