Error in Docker-Compose.yml

Asked

Viewed 41 times

0

Good evening guys, I’m having an error in Docker-Compose.yml, the error shown is as follows:

Erro

and my code is this:

version: '2.4'
 x-database-variables: &database-variables
  SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/anime?createDatabaseIfNotExist=true
  SPRING_DATASOURCE_USERNAME: root
  SPRING_DATASOURCE_PASSWORD: root

services:
  db:
    image: mysql
    container_name: mysql2
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - devdojo_data:/var/lib/mysql
    mem_limit: 512m

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - "./src/main/resources/prometheus.yml:/etc/prometheus/prometheus.yml"
    command: "--config.file=/etc/prometheus/prometheus.yml"
    ports:
      - "9090:9090"
    mem_limit: 128m

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    mem_limit: 128m

  springboot2-essentials:
    image: igordmoura/springboot2-essentials:0.0.2-SNAPSHOT
    ports:
      - "8080:8080"
    environment:
      <<: *database-variables
    mem_limit: 512m

volumes:
  devdojo_data:

Does anyone know what’s causing this mistake?

From now on I thank you all

1 answer

1


It is only a matter of indentation of the second line (below version: '2.4').

To use this YAML Anchor correctly, just remove the indentation from it (staying at the same level of version).

The following should work:

version: '2.4'

x-database-variables: &database-variables
  SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/anime?createDatabaseIfNotExist=true
  SPRING_DATASOURCE_USERNAME: root
  SPRING_DATASOURCE_PASSWORD: root

services:
  db:
    image: mysql
    container_name: mysql2
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - devdojo_data:/var/lib/mysql
    mem_limit: 512m

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - "./src/main/resources/prometheus.yml:/etc/prometheus/prometheus.yml"
    command: "--config.file=/etc/prometheus/prometheus.yml"
    ports:
      - "9090:9090"
    mem_limit: 128m

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    mem_limit: 128m

  springboot2-essentials:
    image: igordmoura/springboot2-essentials:0.0.2-SNAPSHOT
    ports:
      - "8080:8080"
    environment:
      <<: *database-variables
    mem_limit: 512m

volumes:
  devdojo_data:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.